Sprinting decreases energy

Hey, I have an energy bar which decreases when the player sprints and it works, however if I keep sprinting and the bar goes empty, it continues to go down still below 0% so the energy which is restored over time takes ages because it is below zero, so I though clamping the float would help, but I’m unsure how to set this up. See the pic for details and thanks in advance

So, does this not work? It looks good to me.

Hey KingRCooper,

My suggestion would be to have another Boolean check to see whether or not the value for Energy is <= to 0, and if it is True then stop subtracting energy and set your Boolean to false, otherwise continue subtracting energy and set your Boolean to True.

Hi thanks for the reply, if you see the pic attached to this reply, I’ve removed the ‘get’ and ‘set’ for energy decrease and done the minus to 0.1 and when it reaches 0 it doesn’t go any lower, so I’m thinking there’s something wrong with the variable? I’d rather it worked with this variable you see as it runs much smoother with it apart from the below 0 thing

Okay Devin I’ve done as you have said and it works to an extent, and I think I know what the extent is. So if the condition bool is <= than 0 then it does stop reducing the energy, but only when the player releases the button and then clicks back on it. If you see the pic attached it starts with an input action button ‘pressed’ so how can I do it so as soon as it hits 0 it stops reducing, rather than waiting on the player to release and then press again. Thanks

Try plugging in the True result of the new branch into the set of logic that the Released pin of the Input Action is plugged into; the logic that starts with the setting of Is Sprinting to false.

^-- This. You need to check if the Energy is at or below Zero BEFORE you even set the Is Sprinting boolean variable, otherwise your Actor is sprinting and then checking to see if they have the energy TO sprint. So right after the Pressed on the InputAction Sprint node, you want to check if the Actor’s Energy is greater than Zero. If True, do the rest of your sprinting routine. If False, tie into the Released line of logic. (Note I changed the logic check, makes your blueprint look neater.)

Okay so it works apart from the fact that it still goes below 0. Is there something I’m missing?

If I stand still and keep pressing the sprint key it doesn’t go below 0 though, only when the player is moving as well

Other than making sure the Clamp has 0.0 in it, it looks fine. If you want to fix the sprint drain while standing still feature, you can check if Is Moving off of Character Movement.