Topic was automatically imported from the old Question2Answer platform.
Asked By
ErkiElbrecht
Old Version
Published before Godot 3 was released.
Hi,
I am building my first platform game in this engine and i am having problems creating the main controllable character. Right now i am testing if the player is colliding:
if is_colliding():
and setting the jump count to zero so the player can jump again:
jump = 0
but this also means that the player can jump off of ceilings. To solve this i need to test somehow which side of the RectangleShape2D the player is touching and i have yet to find a solution.
You could do get_collider().get_pos() and if the y coordinate is greater than the player’s y, then the object is below. However, that won’t work well for you if you have vertical obstacles/walls, so you’ll also need to use get_collision_normal() to ensure it’s a horizontal surface.
A simpler way to do this is to add a RayCast2D pointing downward. Then you can do if raycast.is_colliding() to allow jumping.
Big thanks, i didnt even think about raycast. Thanks mate