Issue with Moving Platforms and One Way Collisions

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

I’m trying to make functional moving platforms with one way collisions enabled. Both the player and the platform are kinematic2d. Horizontal moving platforms? No problem. But if I try to move the platform vertically, two problems occur:

  1. Moving down, the player “floats” 1 pixel above the platform.
  2. Moving up, the player “sinks” 1 pixel below the platform, and falls through.

Has anyone encountered this before? Are there any tricks to avoid this behavior? I can avoid falling through by disabling one way collisions, but that still leaves the floating/sinking behavior and doesn’t meet my design goals.

This should be fixed in ver. 3.1 (with “Sync to Physics” option). Read more: Godot 3.1 will get many improvements to KinematicBody

pospathos | 2018-12-01 18:17

Yeah, I know. But with no release date, I don’t want to wait around for something that may or may not come soon. Looking for a work-around.

behelit | 2018-12-01 22:48

Hi, as you know, it’s a known bug… according to this link the fix will also be included in next 3.0 release (i suppose earlier than 3.1).

I’ve seen a work arround for angled one way surfaces in this video with ray cast. I think the same should work with platforms moving up. For platforms moving down, perhaps get_floor_velocity ( ) can help you update the velocity of your player (if it’s a kinematicbody2d) so it does not float. If you can share the code, may be we can try some workarround.

p7f | 2018-12-02 00:56

I tested a solution where A. I disabled one_way_collision when the platform was moving up and B. adjusted the offset of the sprite when it was floating. It looked “okay”, was somewhat unreliable (only worked maybe 90% of the time). It could probably work great with a bit more refinement… But it seems like a lot of effort when the horizontal platforms work perfect with no code at all. I might just hold off until 3.1 unless I can figure out a more elegant solution.

behelit | 2018-12-02 21:24

Hi, you coud also build godot from source yourself… it’s really easy and the solution is implemented there. I’ve tested it.

p7f | 2018-12-02 22:23