is_on_floor() is True half of the time, why?

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

Hey there.

I have a player that can only jump when is_on_floor() is true.
No matter what I do, I can never jump (which could be caused by several factors) but I’ve checked the is_on_floor() result as a starting point for my debug.

I’ve checked the following thing:

# Compute stuff, and then do:
motion = move_and_slide(motion, upVector)
print(motion) # prints 0,0 all the time
print(is_on_floor()) # Once False, once True (regular)
print(position.y) # print a float that never changes

So there’s nothing that seem to change (no motion, no position change) but somehow the is_on_floor is alternatively false and true. I have a simple kinematic body 2D with
a capsule collider which stands on a static body with a polygon collider 2D.

Another point I wanted to mention is that I can rotate my sprite so the walls can become the floor; when I rotated several times, I saw that there was ONE direction where I could use the jump. Can’t understand why since everything is really symmetrical and squared, there’s no particular property anywhere

:bust_in_silhouette: Reply From: kidscancode

See this answer & discussion:

I’ve already checked this thread.
I don’t have any remaining part on the vector as I stated it, but I’ve also tried to reduce the safe margin to 0.001, but it didn’t work. Also there’s really nothing special about the collisions so I wouldn’t know what could be tricky to interpret or misleading;

edit: if my y position is a float value, could it be the cause of the problem? Should I round the values at some point after the movement was computed?

Yozamu | 2018-03-29 20:08