How to make stamina bar refill?

I’ve created a stamina bar and whenever my character jumps his stamina decreases by 1 (0.01). I even made the stamina bar to refill 2 seconds after my character jumps by 10 (0.1), but can’t make it repeat, it does it once. I need help with this.


I think this is the wrong picture…

sorry perhaps this

I’m not 100% sure it’s what you want to achieve, but you could try with a while loop.

I’m not quite up to date with how loops behave in new versions but if there was no change the while loop will continuously fire new threads and add stamina each tick rather than waiting until the whole body is executed.

Did you try running this?

Your best bet would probably be using “Event Tick”. You shouldn’t use it if you have hundreds of units at the same time regenerating energy but it’s fine for a few dozen.

I’ve set up a basic example of how to do that:

Each Tick (this means every time anything happens) it will check if the stamina is already full. If not it takes your stamina regeneration per second and multiplies it with “delta seconds”. This is the amount of seconds the tick is behind the last one or in other words how much of a second you process this tick. The result from both will be how much stamina you should regenerate this tick. You add that to your current stamina, clamp it so it doesn’t overcharge and set this as your current stamina.


Hope this helps.


In his image OP uses a jump event rather than a tick event so I feel like the body will be called once every 2 seconds rather than every tick. I didn’t try to run it though and I admit i’m quite curious to know how the whileloop behaves