Sprinting and stamina?

I’m trying to make a first-person platformer demo, and while I managed to plug in sprinting with no issues, I seem to
be having problems getting stamina to work.


Jump Code (adding this picture on the off-chance this is related)

Any input is greatly appreciated thank you.

what did you want it to do, and what is it doing instead?

Sorry, don’t know how I forgot that info. When stamina hits 0 the character is supposed to stop sprinting but right now the player can sprint indefinitely.

its not counting down at all, because your subtraction code is called only once, when the player presses the key. what you should have, is the key press sets a boolean to true, and key release sets a boolean to false, and every Tick, it checks the boolean, to decide whether to add or subtract from stamina.

eventually, you will want to replace the boolean with an Enum of various running states, so you can decide if the player is allowed to run. you could have the enum include things like walk, run, tired, poisoned, injured, crawling, climbing, inAMenu, etc… and in alot of those modes, the player will not be allowed to run. also, eventually, you might want to replace the tick code with a timer, because you probably don’t need to update stamina every frame, you could update it every few frames, and the player wont notice the difference.

I second this. The only thing we do differently is we have the key press/open call different functions on the character (the presses are handled in the controller) and that manages the various movement states and they open/close a gate node that is on the Tick execution path. I like the way that feels over a boolean but that’s personal preference.

Here is a youtube tutorial for it! [Part 21]-Hunger And Thirst System- How to make an advanced FPS game - Unreal Engine 4 - YouTube

Thanks, worked like a charm. There tutorials or whatnot for the Enum you mentioned? That’s a new one on me.

hey ScottSpadea,
just a quick question about those enums. i implemented them into my bp and they work nicely. thanks for the sugesstion. just one thing, u said, “replace the boolean with an Enum”, so instead of having branches check bools, i’d check if the enum has the correct state?
thanks again.