#How to progressively add to players health after taking damage?

12 messages · Page 1 of 1 (latest)

rotund moth
#

Hi ya'll, I'm making a simple game, everything is going well. But I have reached a stage where if player takes damage in game, I want to progressively add to their health.

I did something like this:

func _physics_process(delta):
  if health_bar.value < 10:
     health_bar.value += 1

I thought by putting it in the _physics_process, it will do it progressively. But it's only adding once and then it stopped adding to the health continously. Any help or tutorial will be much appreciated...

#

How to progressively add to players health after taking damage?

tidal nymph
#

you can use lerp or tween

visual solar
#

the physics process tics at 60 times per second per default. so it's happening progressively, but to fast to be noticable. if you'd increase the add value to 0.01 or w.e. you'd notice it. but as you can tell, this probably not a good way of doing it.

i'd suggest adding a timer node, connecting that timer's signal to a function that adds to the health value, and then starting it when the player takes damage.

if you insist on doing it in the physics process, you could do it more controlled by adding the delta together, and counting the time passed that way

polar latch
tidal nymph
#

just don't call that every frame

polar latch
#

Best to use this in some kind of signal setup that fires when the damage was taken. Using a timer node could also work

rotund moth
rotund moth
#

Also, when I print the health_bar.value, it keeps glitching between 0 & 10 after taking damage.

polar latch
rotund moth
#

I finally got it to work