Help with a stamina system

I would like some help on blueprinting a stamina system please. So my HUD is using a progress bar to allow the player to see how much stamina they has. Every time I hit the jump key it reduces that amount. That works fine.

I’d also like to include a sprint system in which it increments stamina down depending on how long you’re sprinting for. I have the sprint key assigned to the left shift, and the stamina reduces since I’m using a float - float. The problem is it only reduces once every time I press the sprint key. I would like it to continuously reduce depending on the duration that I hold that key down. What node(s) should I be using?

I’d also like stamina to increase over time when they’re not sprinting. I’m using an Event Tick with a delay, connected to a float + float. That works fine. But what happens if I want to use more than one Event Tick; say I want to also have a hunger system that subtracts every frame too? How can I get two event ticks working together on one blueprint?

All this is on my ThirdPersonCharacter event graph. Not sure if this is the appropriate place to put all of this.

Thanks!

For this kind of stuff I tend to not want to use the Event Tick as it will be based on the players FPS = not very good solution.
My go to trick to do this kind of stuff usually using a delay and a gate to get it working instead and then repeat that. Here is a small example:

This is not the straight up solution that you can implement, but with a couple of bools and branches you should be able to get both the regen and degen working for your stamina :slight_smile:
Please forgive me using the Jump event and a Set hunger, those where just what I had available in the project that was open :slight_smile:

What tha heck, I thought it could be a fun little project a Friday evening like this :slight_smile:
Here is the blueprint I came up with really fast (and after a couple of beers), so don’t hang me straight away if something is missing :wink:

Edit: Added a short description for the script.

I used a bool called Sprinting? here for later use if you need to know if you are sprinting or not. It’s not really used anywhere in the script right now.
So I used the method I talked about in the first post with a gate and a delay to get a kind of timer effect working.

The gate is a perfect thing to use here as it let’s us open and close the “timer” we created with the delay node. So that when the player releases the “Sprint”-key they stop the timer and decrease of stamina.
And when you release the button it does start to regen.

Big Note: You still need to stop the regen/degen when it reaches its min/max values (like 0 and 100 for example).

Fantastic solution, thanks!!

No problems, glad that I could help you out! :slight_smile:

Since you seem to be well versed in using Blueprints; I would also like the ability to restrict sprinting/jumping if their stamina is too low. Is there a node which would allow me to disable an input button and re-enable it once their stamina is at a certain numeric value? Thanks again!

I don’t know about that, but here is a bit of a cheating way for doing the sprinting part and a better one for jumping :wink:

Jumping is really simple, just use a branch and check if Stamina is below or = a value (U can ofc use any value and check you want)


The Jumping part used here is taken from the Third Person Blueprint example.

Sprinting is a bit harder and I don’t really know “the real way” of doing it, but here is one I have used before and it works.
If we take a look in the CharacterMovement component there is a value called MaxWalkSpeed. I have used this to set the speed of the character a couple of times.
aR0J6y1.png

This script might mess you up, it’s part of a rather complex character movement system I have open right now. But I have used a bool that is true/false depending on if we are moving or not like in the image here:


I then use this in this little script that checks if we are moving and Sprinting and sets the speed accordingly.

So, if we then added another branch for the stamina check like this we would get the desired effect that we can’t sprint when stamina is low:

Hopefully this can help you a little bit on the way at least :slight_smile:

Edit: It perhaps got a bit messy when I used my script from a project with another approach than you have now. But hopefully you get the idea of how to do it :slight_smile: I also spotted a problem, in the last image the stamina-checking branch should be the opposite way around. With my little error there you can only jump when stamina is 0 :wink:

Instead of disabling your input entirely, you could possibly use the Compare Float node against the current stamina and whatever value you assign as your minimum requirement to jump. If it’s below that number, do nothing, and if it’s equal or above, then execute whatever your input is supposed to accomplish. So basically: InputAction Jump/Sprint/Etc. > Compare Float > perform actions if >= minimum action requirement.

Hope that helps.

Great answer! That might actually have explained it way more easy to understand than my myriad of pictures and stuff :slight_smile:

I just used the => sign and that worked out perfectly, thanks.

Everything else I’ll have to dive into in a bit to see if I can get some of that functionality working. Thanks again! :slight_smile:

There you go, great to hear!
Just make another post here on the forums if there is any further problems, there is always someone that has experienced the same problem before :slight_smile:

That did it, thanks!

Sparven this is great:)
For me this is one of the best solutions for stamina system!
I’ll try this with character attribute system.

Awesome, glad I could help! :slight_smile:

I’m still in the learning of process myself, and your guys’ posts are helping me just as much. Thanks!