+1 vote

I'm making an auto-scrolling platformer, with the camera following a player moving at a constant horizontal speed.

I'm using moveandslide to move and also go up and down slopes, however this slightly reduces the horizontal speed. Not enough to notice, but it will be a music-based game, so the cumulative effect would put it out of sync.

What's the best way around this? I've tried increasing the max_slide_count, but it doesn't make a difference. I even tried using move and collide to simply move the player, then try and adjust vertically as much as much necessary using a ray cast, but my code is obviously no good - the player gets stuck and doesn't move. This seems over-complicated to me anyway, I'm sure there's a better way.

moveandcollide code just in case:

last_collision = move_and_collide(delta * linear_vel, true, true, true)
var offset = Vector2(0, 0)
if last_collision:
    var space_state = get_world_2d().direct_space_state
    var attempt = global_position + delta*linear_vel
    var collision_shape = Physics2DShapeQueryParameters.new()
    if last_collision.normal.y > 0:
        var collision = space_state.intersect_ray(attempt - $Edge.position + RAY_LENGTH, attempt - $Edge.position, [], collision_mask & (2+4+32))
        offset = collision.position - (attempt - $Edge.position)
    elif last_collision.normal.y < 0:
        var collision = space_state.intersect_ray(attempt + $Edge.position - RAY_LENGTH, attempt + $Edge.position, [], collision_mask & (2+4+32))
        offset = collision.position - (attempt - $Edge.position)
    else:
        die()
    position += delta*linear_vel + offset
in Engine by (65 points)

I don't have any experience implementing this, but there's a bit of information about it in this post: https://godotengine.org/article/godot-31-will-get-many-improvements-kinematicbody

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.