Increasing and decreasing value over time

Hi, I need to Decrease a float variable when a button is held down and then have it Increase when the button is released.

I’m trying the make a jetpack that has a cooldown period (like in halo). So when the player holds down the jetpack button the character will fly but only till the variable hits 0 then when the button isn’t pushed the value gets increased so the player can use the jetpack again.

Could anyone show be how to do this in blueprints?

This is how I’d do it. I tried commenting each section to explain what it does in each of those bits. I didn’t test this, but it should:

Constantly regenerate your jetpack energy while it’s not being used, up to a maximum of 100.
Pressing space bar stops the regeneration, starts draining the energy, “adds movement”
then when it runs out of energy - disables everything, triggers a cooldown, turns the regeneration back on.
Releasing space bar turns on the regeneration, stops the energy drain, stops adding movement and turns off cooldown after a 10 second delay.

You should also remember that it’s dependant on framerate currently, so to get around that you should use delta time to affect any float values you’re adding or subtracting to make sure it does the same thing regardless of framerate. And that with a high framerate the values that I’ve clamped it at will only take around a second to drain from full to empty.

Cheers that helped a lot :slight_smile:

Wait, you can use a ‘?’ character in variable naming? Now thats new. I am fairly sure you can’t do it in C++, or any language.

Apparently so. I’ve been using them in a lot of places in blueprints. Reminds my brain to consider bools as questions if I start getting confused with them.

Yeah, they work fine in blueprints. I guess they strip them off in some stage of the compiling. I think they are great as earlier speaker said to keep track of bools as questions and such situations. They keep my brain from melting sometimes :slight_smile: