# losing stamina while holding shift and not moving

**URL:** <https://forums.unrealengine.com/t/losing-stamina-while-holding-shift-and-not-moving/1156620>\
**Category:** Blueprint\
**Tags:** unreal-engine, question, Blueprint\
**Created:** [May 6, 2023, 3:11pm UTC](https://forums.unrealengine.com/t/losing-stamina-while-holding-shift-and-not-moving/1156620 "2023-05-06T15:11:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![adnemannen](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@adnemannen](https://forums.unrealengine.com/u/adnemannen)\
**Post date:** [May 6, 2023, 3:11pm UTC](https://forums.unrealengine.com/t/losing-stamina-while-holding-shift-and-not-moving/1156620/1 "2023-05-06T15:11:32Z")

</div>

hi. i have added stamina to my game but when i am not moving and holding shift i lose stamina. this is the code i am using.

 ![image_2023-05-06_170909125](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/2/8/d282a933a3fed04a56a963154d4496949a6044d2.png)

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/5/c/45c18164e934e382a7c3cb14fd9aebd8e9f6aeb9.png)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/f/1/0f1e5bd4f95083ec0996dce17604ed8986f16ecf.png)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/2/b/b2b4db8fca2bd540b363487b76486ccfbd805365.png)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/8/e/68ef4a02df33c24152d5b9dcad9af00b271de005.png)

pls help.

---

<div class="post-metadata">

**Author:** ![L1z4rD89](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/l1z4rd89/32/1194537_2.png) [@L1z4rD89](https://forums.unrealengine.com/u/L1z4rD89)\
**Post date:** [May 6, 2023, 3:36pm UTC](https://forums.unrealengine.com/t/losing-stamina-while-holding-shift-and-not-moving/1156620/2 "2023-05-06T15:36:52Z")

</div>

Hey @adnemannen

You are decreasing your stamina before you check if you are currently sprinting. So in your DrainStamina event use the branch with IsSprinting as the first node. Then on the True output decrease the stamina.

And your IsSprinting should not just only be set by your InputAction. You also have to check if your characters velocity is greater than 0.

---

<div class="post-metadata">

**Author:** ![adnemannen](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@adnemannen](https://forums.unrealengine.com/u/adnemannen)\
**Post date:** [May 6, 2023, 3:59pm UTC](https://forums.unrealengine.com/t/losing-stamina-while-holding-shift-and-not-moving/1156620/3 "2023-05-06T15:59:38Z")

</div>

Hi @L1z4rD89

I have tried that.

I tried to define the is sprinting variable with Get velocity if velocity is equals or greater set is sprinting

But it didnt work

---

<div class="post-metadata">

**Author:** ![L1z4rD89](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/l1z4rd89/32/1194537_2.png) [@L1z4rD89](https://forums.unrealengine.com/u/L1z4rD89)\
**Post date:** [May 6, 2023, 4:30pm UTC](https://forums.unrealengine.com/t/losing-stamina-while-holding-shift-and-not-moving/1156620/4 "2023-05-06T16:30:51Z")

</div>

Can you show how you did it? You can get the velocity and then break this vector and check if x or y is greater than 0. And did you change the branch position?

---

<div class="post-metadata">

**Author:** ![adnemannen](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@adnemannen](https://forums.unrealengine.com/u/adnemannen)\
**Post date:** [May 7, 2023, 4:46pm UTC](https://forums.unrealengine.com/t/losing-stamina-while-holding-shift-and-not-moving/1156620/5 "2023-05-07T16:46:47Z")

</div>

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/b/7/2b73dd474cbd80d4deed440fb175f0991e53ac1f.png)

---

<div class="post-metadata">

**Author:** ![L1z4rD89](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/l1z4rd89/32/1194537_2.png) [@L1z4rD89](https://forums.unrealengine.com/u/L1z4rD89)\
**Post date:** [May 8, 2023, 6:51am UTC](https://forums.unrealengine.com/t/losing-stamina-while-holding-shift-and-not-moving/1156620/6 "2023-05-08T06:51:16Z")

</div>

Hey @adnemannen

here is a small example:

Set the **MaxWalkSpeed** for the character in the beginning

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/2/1/42100d7265e8f1b074cb0a828948515d746d715e.png)

Set **IsSprinting** , then set the corresponding **MaxWalkSpeed** , clear a timer if there is one via the **TimerHandle** and then set a timer for consuming the stamina or regenerating stamina. These timers use a different time for looping, **ConsumeTime** = fast 0,01, **RegenTime** = slow 0,1.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/8/b/08b032edc648ce88b212f27c750820d11c47092c.png)

Simple move input

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/2/6/c268aeb6006e41f9644f392c2d94cbe8e4d45f14.png)

The looping event called **Stamina**. Yes you can use an event for a **SetTimerByFunctionName**. First, we check if the character is sprinting AND is moving.  
If the character does both, we check if the **CurrentStamina** is above 0 and then decrease it.  
If the character does neither, we check if the **CurrentStamina** is less than the **MaxStamina** and then increase it.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/1/3/b1353b45ee10546c3b618a39a20a6e358424b8c4.png)

Starting values =\>  
CurrentStamina = 100  
MaxStamina = 100  
IsSprinting = False  
ConsumeTime = 0,01  
RegenTime = 0,1  
WalkSpeed = 300  
SprintingSpeed = 600

In your case it would look like this:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/f/b/efb3dd31226cd98b200b594d02f8930eb49a58f2.png)

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/6/f/56f5b35c8d10f9aef44c454a875ade53b2559485.png)

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/8/0/780eae8ecb3d1bd3f2e048fd64c7c4d2911a47ff.png)

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/a/3/5a3121a03ac4839403e45b7b3f533adf45f752bd.png)

Keep in mind that both ways are currently only changing the stamina and do not stop the character if the stamina is 0.

Here is another example:

> [@I cant get my progress bar to work as i want (in blueprints)](https://forums.unrealengine.com/t/i-cant-get-my-progress-bar-to-work-as-i-want-in-blueprints/632850/4):
>
> I created a 3d person template. Inside the ThirdPersonCharacter I added these values: Stamina: Float MaxStamina: Float StaminaDepleted: Boolean WidgetRef: UserWidgetObjectReference EventBeginPlay: Sprint: Refuel: And inside the widget: [image] Edit: [StaminaPoints.zip - Google Drive](https://drive.google.com/file/d/1eZj8i3ckdiZNuDEpRmIJRTx8NS29xpd3/view?usp=sharing)
