0 votes

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.

Thanks in advance !

in Engine by (20 points)

2 Answers

+1 vote
Best answer

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.

by (21,920 points)
selected by

Big thanks, i didnt even think about raycast. Thanks mate

0 votes

add 4 segment collision shape for each side, its a bit slow.. but its the most simple way to do it

by (18 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.