0 votes

I made a condition for the regeneration of the health of my character. But it happens very quickly.

func _process(delta):
if food > 95:
    yield(get_tree().create_timer(3.0), "timeout")
    health += 1
if health > 100:
    health = 100

I tried to change the value to a smaller one

func _process(delta):
if food > 95:
    yield(get_tree().create_timer(3.0), "timeout")
    health += 0.01
if health > 100:
    health = 100

But that is not what I need
I would be grateful if you indicate where I was wrong

in Engine by (71 points)

2 Answers

+1 vote
Best answer

Instead of health += 1, use health += delta to add 1 HP every second. This is because delta corresponds to the time passed in seconds since the last rendered frame.

by (11,917 points)
selected by
+1 vote

If I understand your question correctly, I think your problem is that the part in the if-statement 'food > 95' is executed several times (I don't think the timer prevents the game from calling the process function again). Try to do something like

if food > 95:
    food = 95 #In order to prevent the program from jumping to this part again
    yield(get_tree().create_timer(3.0), "timeout")
    health += 1
if health > 100:
    health = 100
by (25 points)
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.