Is there a way to not move a KinematicBody2D along with a moving platform?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By InterDan

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 “move_and_slide”? 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)


:bust_in_silhouette: Reply From: InterDan

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.