Falling Through Moving Platforms

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

I am working on vertical moving platforms which are KinematicBody2Ds with rectangular CollisionShape2Ds. The collision shapes have one_way_collision = true and a snap threshold of 1 pixel.

I move the platforms with a Tween, and both the tween and the KinematicBody2D are synced_to_physics.

Sometimes when my player lands on platforms that are moving upwards, he lands briefly before falling through the platform on the next frame.

I think what happens is that the player lands on the platform (changing his state to idle) and in the same frame the platform is moved a few pixels up, which puts the bottom of the player below the top of the platform causing the player to fall.

It only happens periodically when jumping onto the platforms, and happens when the player has very low y-velocity.

I though syncing everything to physics would avoid this, but it still happens periodically.

What gives, and is there a way to avoid this?

Ideally, I don’t want to increase the collision shape’s snap threshold, since I don’t like the feeling of snapping up one-ways.

My player is a KinematicBody2D and I move him with move_and_slide_with_snap().

You could make the player a child of the platform using an area with body_entered.

Magso | 2019-05-16 16:43