Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | bribat123 |
I am creating a 2D game. At one point of the game my player jumps onto a moving object. The first time the player lands on the object, it is fine as the player stays on top of the body collision object. However then the collision objects moves vertically upward, but then the player is falling through. How can I prevent this from happening?
Player is a Kinematic Body 2D
Moving with move_and_slide
Collision object is Collision 2D
Collision shape is a line segment
You’ll need to be more specific about your setup. It’s clear the player is a KinematicBody2D, but what is the floor? “Collision 2D” is not a node type.
Is it also a KinematicBody2D? If so, how are you moving it?
Is it a StaticBody2D? If so, you will need to change, as static bodies can’t be moved.
Also, you’ll probably need to switch your player’s movement to move_and_slide_with_snap()
, as that will help keep you “stuck” to the object when it moves vertically.
kidscancode | 2020-01-19 07:44
The player is a KinematicBody2D. I use move_and_slide to move it because move_and_slide_with_snap causes is_on_floor to stop working.
The floor body is a StaticBody2D. The body does not move. However the body is a parent of a CollisionShape2D that moves up and rotates a bit during an animation sequence.
I want the player to be able to stay on the CollisionShape2D as it moves. Is it possible or not?
bribat123 | 2020-01-19 15:11
move_and_slide_with_snap()
does not break is_on_floor()
unless you’re doing it wrong.
Animating the collision shape without moving the body is still moving it. I honestly can’t say I’ve ever tried such a thing, but I would not expect it to work well.
I’ve done a lot of experimenting with methods of handling moving platforms. To my mind, the best solution is this one: http://kidscancode.org/godot_recipes/2d/moving_platforms/
kidscancode | 2020-01-19 18:14