I’ve created a stamina system in UMG that makes the player unable to jump when empty. How do I make it so that it starts to refill if the player waits a second or two?
There are many ways, for example check input axis value and if it is zero set refill variable to true, else set it to false. Then in Tick event increase stamina if refill variable is true. Although it is not very good solution (a lot of unnecessary variable checks and sets) it should do the job. The next step is to optimize it.
EDIT: I forgot you wanted to have a delay before refill starts so that won’t do it, sorry.
VRLtqq’s idea works fine even with a delay :
But you have two situations to solve. First when player press permanently jump. Second when he press it repetitively.
Create two boolean variables “Isjumping” and “Jumped”
On input action jump :
On pressed: Set variable “Isjumping” to true, then do your jump system.
On released:Set variable “Isjumping” to false.
Then you know when the player release jump button.
Between your “set IsJumping” and your jump system, add variable “Jumped” set to true.
Then you know when your jump button have been pressed without released consideration.
On event tick : do a sequence : on 0 : delay 1 s / set “Jumped” to false.
On 1 : delay 0.5s / branch with “jumped as condition” :
On true : nothing (player has jump since less than a seconde)
On false : branch with “IsJumping” as condition.
From this new branch :
On true : nothing (player has not released jump button)
On false : We now know that since a second (in fact since 1 to 1.4 s, you have to adjust values, i used different ones to show) the player have not click on jump and is not pressing it yet.
Then we can add our refill system : Set fuel = fuel + .25.
Thanks for the answer. The only problem is that I already have an event tick in the character blueprint and can’t use another. Is there a way round this?
Sure : Use the sequence and set all your different tick events on a different output.
Call this event after every action that you want to trigger the recharge.
Have your stamina regen amount multiplied by your stamina regen rate (Set default value to 1 in your details panel).
Check it with axis values to see if the player is still (or you could see if they have zero velocity) if you want to force the player to have to stand still for the recharge.
Thanks Xendran, it seems really better than what i’ve learned from tutorials i found before. And i suppose that adding a condition to check released will be enough. I’ll have to try this. Thanks again.
One reason i have this bound to an event is because i didn’t want sprinting to trigger the stamina delay, but have other things still trigger it.
I have the Dark Souls stamina system pretty much completely replicated in blueprint (and improved upon in a way that massively improves balance and playstyle variance and dynamics, but that’s a secret ;o ), so i’ve done lots of messing around with ways to get various things to work with it.
It also isn’t bound to any direct input (or variables), only to come after an action has been taken as a result of said input so you can incorporate it with things that are activated both on key pressed and key released.
Because it’s also not bound to any player variables, you can trigger the delay externally without adding extra checks to your delay blueprint. This means enemies could have attacks that trigger your stamina regen delay.