0 votes

I want my player character to not move with the platform they're standing on, but so far I can't find a good solution.

I tried negating the movement in physics process with this line both after and before the
"move and slide" function:

    move_and_collide(- get_floor_velocity() * delta)

And it kind of works, but if the movement of the platform puts the character over a static floor, the KinematicBody2D will register the velocity of the static floor and won't negate the movement of the platform, effectively moving the player along with it.

Is there a way of just disabling the automatic application of "floor velocity" on "moveandslide"? Or setting a limit of maximum "floor velocity"? (If I manually apply that limit it will dump the falling velocity and give problems with other game mechanics)


in Engine by (28 points)

1 Answer

0 votes
Best answer

Hi all, it seems that trying to find a solution I added a second "move and slide" function at the beginning of the physics process, which was messing the subtraction of the floor velocity on the main "move and slide". That's why the solution above wasn't working correctly. Now that I have just one "move and slide" function, it works nice! Here is what the piece of code looks like for anyone curious:

    var remainder = move_and_slide(motion,  Vector2(0, -1))
    move_and_collide( - get_floor_velocity() * delta)

I guess that if you wanted to not apply the movement of just certain type of platforms you could use "get slide collision()" and check for the platform tag before applying the subtraction.

by (28 points)
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.