Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Paar |
Hi. I have a problem with function “is_on_floor()”. My object (KinematicBody2D) is standing still on another object (StaticBody2D) and is being constantly pulled down by the gravity with the function “move_and_slide(velocity, Vector2(0, -1)”. Now, if I print the function “is_on_floor()” every frame I can see that it returns “true” only on every fourth frame (project is locked at 60 fps). Is this correct behaviour?
Debugger:
False
False
False
True
False
False
False
True
_physics_process() is called at fixed intervals, while _process() is called at variable intervals. (I’m not sure how fixing the fps works.) Are you perhaps calling move_and_slide() in the physics processing but the print() statement in normal processing? Maybe something along these lines explains your result.
Diet Estus | 2018-03-20 15:06
Well, I think I have found the problem. First a snippet from my code:
if is_on_floor():
speed.y = 0
speed.y += GRAVITY * delta
if speed.y > MAX_FALL_SPEED:
speed.y = MAX_FALL_SPEED
For some reason when the speed.y is reset to 0, the is_on_floor() function stops working properly. I have checked the remaining vector after the reset and it’s (0, 1.666667) with false floor flag. Then it’s (0, 3.333333) for the next frame, again with false floor flag In the third frame it’s (0, 0) with the floor flag set to true. Why is the collision not detected right in the first frame? What’s more, the get_slide_count() always returns 0 even though there is a collision and get_slide_collision(0) returns a null object. Probably a bug.
Paar | 2018-03-20 16:51