Sprinting consumes no stamina if key already held

I have a blueprint in the ThirdPersonCharacter to do sprinting. Sprinting is activated by holding Left Shift and will consume stamina as long as it’s held, then once released stamina will regen. If you run out of stamina you stop sprinting and regen won’t start until the key if released. This is working great. However, if you hold the key while the character isn’t moving and then begins moving, no stamina is consumed. For the life of me I cannot figure out how to perform the stamina decrease event is the key is pressed before movement. Please can someone help?

Ps sorry for the disjointed image; the blue print was too big to get all in one screenshot

I am sorry but your screenshot is way too small is there a way to make it bigger

Is character at 1000 walk speed if you held the key down before running?

Character should be at 0 walk speed because they aren’t moving

And it also wouldn’t set the walk speed to 1000 when pressing because of the vector check

You can try just bypassing that vector check. Setting the Max Walk Speed can be done regardless if the character is moving or not.

I’m new so this might not be the most elegant solution, and I know it’s best to minimize the number of calls you make on the event tick, but perhaps this will help? 84ac04d185a54aa5b7b4285ddf55e8871c188497.jpeg

The vector check was there though to make sure the character is actually moving, otherwise stamina was decreasing when the button was held regardeless

Ah ok. Maybe try moving the vector check to the decrease stamina event, right before that first current stamina check branch. That way when shift is pressed, it is running the decrease stamina event but shouldn’t go through if the character is not moving.

To before the timer or just after the actual event call? Either way I’ll try that tonight, thank you :slight_smile:

I may try this as well, thank you!

In your Decrease Stamina custom event call, currently you first check if the Current Stamina is less than or equal to 0. Do the vector check right before that check in the actual Decrease Stamina event.

This works perfectly! You’re a genius, thank you so much!

Also, instead of doing it on tick, like Sarrin23 was suggesting, you could make a timer by function(that starts on event begin play) and have it check at a smaller interval rate like five times per second. If you were frame capping at 60fps, changing that function to only update five times per second would result in a 92% decrease in it’s load and it would barely even be noticeable to a player.

Obviously, there are far more efficient ways to go about the check though and event driven would be the way to go.

omg, duh! Thank you! This will definitely help me cutdown on calls-per-tick.