How to drain slow motion ability via blueprint?

Hello I am still a novice and would appreciate the help. I have a working slow motion ability for my character. When a button is pressed time slows down and when it is pressed again time returns to normal. It also has a cool down period.

What I am struggling with and need is:

  1. A way to drain the ability (like sprint stamina) so that when it hits 0 it exits the state
    and starts to regenerate the ability.
  2. Still have the ability to manually toggle the ability with a button press.
  3. This will be a special ability with a progress bar.

Any help would be appreciate and thanks in advance.

Add a float variable to keep track of the stamina (or whatever) necessary to use the ability. In the EventTick, you check whether the ability is currently active (comparing Get Custom Time Dilation to 1). If it is, you decrease the variable by the Delta Seconds input value. Otherwise, you increase the variable. Either way, you clamp the result between 0 and the maximum allowed value.

58451-slowdownstamina_eventtick.png

If the value reaches 0, you stop the slow motion. Similarly, if the value reaches the maximum value, you might want to inform the player that the ability is available again.

Obviously, you’ll need to add a check whether the player has enough stamina left in your current code.

From a design perspective, I’d recommend to either only allow triggering the ability if the stamina is currently at maximum (but then keep it up until the stamina is depleted or the player turns it off again) or to define a minimum value the stamina needs to have for the ability to be available. It’s frustrating to attempt to use an ability that immediately becomes unavailable because the stamina was too low.

Works great thank you