Why is is_on_floor() working on _process but doesn't on _physics_process()?

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

Hello guys! Probably a noob question but I tryed to find an answer to it without success in multiple places. So, why this is_on_floor() works fine on _process but doesn’t on _physics_process? Thanks in advance!

extends KinematicBody2D
    
    var direction=Vector2()
    const UP = Vector2(0,-1)
    
    func _physics_process(delta):
    	direction.y+=10
    	if Input.is_action_pressed("ui_right"):
    		direction.x=100
    	elif Input.is_action_pressed("ui_left"):
    		direction.x=-100
    	else:
    		direction.x=0
    	if is_on_floor():
    		direction.y=-500
    	move_and_slide(direction,UP)

Ok, after some testing I’ve got that if I put the is_on_floor() test under the move_and_slide() it works. Apparently the is_on_floor() is just updated after move_and_slide() has been called. But just for curiosity, anyone knows why they behave differently inside _process() and _physics_process()?

rhennig | 2020-03-26 17:46

Apparently the is_on_floor() is just updated after move_and_slide() has been called.

Yes, that’s clearly stated in the documentation. However, even if one ignores this and calls is_on_floor to early, that should just cause a delay of one frame.

Anyone knows why they behave differently inside process() and _physics_process()?

In my tests they didn’t. And I don’t see any reason why they should, apart from the fact that they might be called at different rates, thus the length of delay may vary.

What exactly is not working for you?

njamster | 2020-03-27 09:56