is_on_floor()
is not working but is_on_wall()
works but you aren't supposed to walk on walls. It also works for ceilings too. How do I make them work separately. The player is a box. I am using GDscript.
is_on_floor() not working
You may have to set velocity y to 0 when is_on_floor() is true.
That is not the problem. If print something inside the is_on_floor()
. It does not get printed and I can't jump. Only walls, work for everything. I need to fix both.
Do you have gravity in your game?
From what I remember, you have to have a constant downwards force (like gravity) for is_on_floor
to be set to true
. If there isn’t a downwards force causing a downwards collision (even if really slight) then it doesn’t trigger is_on_floor
being true.
I think in the past how I handled this was I added a very slight amount of downward gravity that is always added to the velocity prior to calling move_and_slide
or move_and_collide
.
The game has gravity but TwistedTwigleg's solution is not working.
Dunno if you already got an answer to this, but if you're using move_and_slide() or to move the character, the second, optional argument is up_direction. It takes a vector and tells the function what "up" is and, by proxy, what a floor is. You can pass the vector constant Vector2.UP (for 2D, there's probably an equivalent in 3D) into the argument or define your own. Hope that helps.