Why doesn't the physics process repsect my timer?

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

when I run the scene my sprite starts moving even though the timer has not reached zero

extends KinematicBody2D
    var speed = 10
    var factor = Vector2(1,1)
    var actual_pos = position


var pos_des = Vector2(384,256)

    enter code here

func _on_Timer_timeout():
	set_physics_process(speed)
	pass
	
	
func _physics_process(speed):
	if pos_des != position:
		if actual_pos < pos_des:
			position.x += factor.x
			position.y += factor.y
			actual_pos = position
		if actual_pos > pos_des:
			position.x -= factor.x
			position.y -= factor.y
			actual_pos = position

I have alredy solved xddd, in the function ready I needed to disable it

 func _ready():
	set_physics_process(false)
	pass

kevin117 | 2021-05-18 21:58

This solution help alot! Thank you very much .

ProroboAI | 2022-10-23 22:37

:bust_in_silhouette: Reply From: timothybrentwood

From the docs:
"void _physics_process(delta: float) virtual
Called during the physics processing step of the main loop. Physics processing means that the frame rate is synced to the physics, i.e. the delta variable should be constant. delta is in seconds.

It is only called if physics processing is enabled, which is done automatically if this method is overridden, and can be toggled with set_physics_process()."

Basically _physics_process() is called once a physics frame automatically with a value delta that acts as a constant you can use to convert your units from per pixel to per second etc. set_physics_process() expects a bool that turns physics processing for the object on or off.

If you want to have your sprite not immediately move, but move after a timer times out make the following changes:

func _ready():
    set_physics_process(false)

func _on_Timer_timeout():
    set_physics_process(true)

_ready() is a vitual built in function like _physics_process() that automatically gets called when all of the children of that node are in the scene tree and _ready() themselves.