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.
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
Please forgive me using the Jump event and a Set hunger, those where just what I had available in the project that was open
What tha heck, I thought it could be a fun little project a Friday evening like this
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
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).
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!
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.
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:
Hopefully this can help you a little bit on the way at least
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 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
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.
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