_process work twice before the position move

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

I try to move my player to start point and reduce life when it fall. But that print(“Dead”) func call twice before it move to start position. So once the player fall, it reduce two life and print “Dead” twice in Output. Please tell me if there is anything wrong with my code.

func _process(delta):
	if transform.origin.y < -5:
		transform.origin = Vector3(0,4,0)
		life =- 1

Might be a race problem because _process is called for each frame. So there are some frames before you transform to the new position.
It gets called e.g. for transform.origin.y == -6 and transform.origin.y == -7.

Try it with a state switch alife = true and switch to false before transforming and back to true after print. Not sure if the race window is then small enough.

Or use collision signals.

arlecchino | 2019-03-22 20:23