0 votes

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
        print("Dead")
in Engine by (12 points)

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.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.