# Sprinting and stamina?

**URL:** <https://forums.unrealengine.com/t/sprinting-and-stamina/341496>\
**Category:** Blueprint\
**Tags:** platformer, sprint, stamina, unreal-engine, Blueprint, question\
**Created:** [December 15, 2015, 5:48am UTC](https://forums.unrealengine.com/t/sprinting-and-stamina/341496 "2015-12-15T05:48:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nintendogeek01](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@nintendogeek01](https://forums.unrealengine.com/u/nintendogeek01)\
**Post date:** [December 15, 2015, 5:48am UTC](https://forums.unrealengine.com/t/sprinting-and-stamina/341496/1 "2015-12-15T05:48:12Z")

</div>

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.

Sprint/Stamina

 ![70656-sprintstaminacode.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/c/1/cc1c170c69e41d79110f37860246a12e16e9b3ba.jpeg)

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

 ![70657-jumpcode.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/c/b/fcb4bb7189cd17ea76ab8539df23dd2f8fbbdcb6.jpeg)

Any input is greatly appreciated thank you.

---

<div class="post-metadata">

**Author:** ![ScottSpadea](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/scottspadea/32/1194682_2.png) [@ScottSpadea](https://forums.unrealengine.com/u/ScottSpadea)\
**Post date:** [December 15, 2015, 7:18am UTC](https://forums.unrealengine.com/t/sprinting-and-stamina/341496/2 "2015-12-15T07:18:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nintendogeek01](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@nintendogeek01](https://forums.unrealengine.com/u/nintendogeek01)\
**Post date:** [December 15, 2015, 7:21am UTC](https://forums.unrealengine.com/t/sprinting-and-stamina/341496/3 "2015-12-15T07:21:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ScottSpadea](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/scottspadea/32/1194682_2.png) [@ScottSpadea](https://forums.unrealengine.com/u/ScottSpadea)\
**Post date:** [December 15, 2015, 7:25am UTC](https://forums.unrealengine.com/t/sprinting-and-stamina/341496/4 "2015-12-15T07:25:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_ecb5cc49](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_ecb5cc49](https://forums.unrealengine.com/u/anonymous_user_ecb5cc49)\
**Post date:** [December 15, 2015, 10:05am UTC](https://forums.unrealengine.com/t/sprinting-and-stamina/341496/5 "2015-12-15T10:05:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![MCaddict](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MCaddict](https://forums.unrealengine.com/u/MCaddict)\
**Post date:** [December 15, 2015, 2:07pm UTC](https://forums.unrealengine.com/t/sprinting-and-stamina/341496/6 "2015-12-15T14:07:41Z")

</div>

Here is a youtube tutorial for it! [[Part 21]-Hunger And Thirst System- How to make an advanced FPS game - Unreal Engine 4 - YouTube](https://www.youtube.com/watch?v=2h_mpHgbkcI)

---

<div class="post-metadata">

**Author:** ![nintendogeek01](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@nintendogeek01](https://forums.unrealengine.com/u/nintendogeek01)\
**Post date:** [December 15, 2015, 5:10pm UTC](https://forums.unrealengine.com/t/sprinting-and-stamina/341496/7 "2015-12-15T17:10:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![CiteNoir](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CiteNoir](https://forums.unrealengine.com/u/CiteNoir)\
**Post date:** [January 15, 2017, 10:05pm UTC](https://forums.unrealengine.com/t/sprinting-and-stamina/341496/8 "2017-01-15T22:05:26Z")

</div>

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.
