How do I stop my character from sprinting until the stamina bar is fully replenished

Isn’t sprinting just setting Max Walk Speed? Show us your StartSprinting event.

If you’re are indeed setting Max Walk Speed, just add a boolean variable called “CanSprint” and set it default value to true. In StartSprinting, if CanSprint is false, set Max Walk Speed to walking speed. If it’s true, set Max Walk Speed to your sprinting speed.

Then you just need to set CanSprint to false when you run out of stamina and to true when it has regenerated. So in your Drain Stamina graph, set CanSprint to false BEFORE the StopSprinting node and replace the StopSprinting node with the StartSprinting node (since this node will trigger walking if CanSprint is false).

And finally in the RegenStamina graph, connect the first branch node’s True pin where you set CanSprint to true.

That should do it. Let me know if your setup for sprinting is different than what I mentioned.

edit: I’ll make you an update graph in a moment. I have a few errands to run first.

Something like this should work. This will automatically start sprinting once stamina has been regen and the input action is still active.

Note that I don’t know what else is in your StartSprinting graph. The stuff I added needs to be before the existing nodes.

Hey thanks for the reply, tried to


implement this method with my current start sprint and i have no clue what to do, my character literally cant move now.

Your help would be kindly appreciated :slight_smile:

Ur blueprint that I Implemented ^^

I’ll try a local project and let you know.

Looks like the Delay node is unreliable and gets ignored if it’s called more than once at a time. So you basically have to use the tick event. Here’s what I have.

Replace Left Ctrl event with your own event that triggers sprinting, but keep the nodes.

Set defaults for RegenPerSecond to 20.0 and DrainPerSecond to 40.0 to have the same effect as your old BP.
Set WalkSpeed and SprintSpeed to 350.0 and 600.0 respectively.

Leave the rest as default.

In your BeginPlay event, add these nodes:

image

Then create these three functions.

Most of this is similar to what you had before. The biggest change is the UpdateSprint function.
This is where we check for a state change. If IsRegen is true and it’s done regenerating, then set it to false and check if WantSprint is true. If so, set the character sprinting.

If IsSprinting is true, check if stamina is at zero. If so, set it to false and set the character walking. Now, if IsSprinting is false, we also have to check if WantSprint is true in case we manually activated sprinting, but only if Stamina is maxed.

A side effect of this is that if you stop sprinting early, you still have to wait until stamina goes to max before sprinting again. If you want a different effect, you’ll need another boolean for when you hit zero stamina. Now you can check for max stamina OR HasHitZeroStamina is false before setting a character to sprint.

You might be able to simplify this a bit with a state graph. But that’s a whole other topic.

Oh, and I set Stamina to float. You can cast it to an integer for your UI.