losing stamina while holding shift and not moving

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

pls help.

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.

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

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?

Hey @adnemannen

here is a small example:

Set the MaxWalkSpeed for the character in the beginning
image

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.

Simple move input

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.

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

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:

1 Like