My Blueprint for sprinting with a cooldown

I’ve poked around to get a sprinting mechanic that lasts 5 seconds (Sprint Timer), goes on a 10 second cooldown (Sprint Cooldown Timer) and here it is:

Used variable types and names:

  1. float “SprintTimer”
  2. float “SprintCooldownTimer”
  3. boolean “isCoolingDown” (set to false by default)

The logic behind it assuming someone just pressed Left Shift and hasn’t sprinted beforehand:

  1. When Left Shift is pressed, go to the branch statement (aka: if statement)
  2. Check to see if the boolean “isCoolingDown” is true or false.
  3. Assuming that this is the first time someone is sprinting, the boolean is false by default and therefore, will sprint for 5 seconds (the 5 second delay that utilizes SprintTimer).
  4. Once the 5 seconds of sprinting is up, set the cooldown to true (by setting isCoolingDown to true).
  5. IMPORTANT: You need to make sure that the sprint properly enters cooldown, that’s why there is another delay after the isCoolingDown is set to true. After this delay (which lasts 10 seconds because that’s the length of the sprint cool down ), set isCoolingDown to false.
  6. Once the player lets go of the sprint button and presses it again immediately, the player can thus sprint again.

http://i.imgur.com/mgyxeTV.jpg

If you’re reading this, you may be wondering: “But rayDawg, why didn’t you just connect the same variables multiple times such as the character movement variable instead of creating multiple copies??”

The answer is because I wanted to make this look as clean and understandable as possible so anyone can “get it” at first glance.

Not bad, but using delays like this an antipattern. It would be better to implement a FSM properly. It looks quite simple though, which is good.

I have no idea what is an FSM you’re referring to. I just thought someone would like to use this and improve upon it in some manner. There are still bugs to it, but it’s better than having no search results.

Take a look at the Gate element. You can find a nice example in the point and click project template in a Blueprint called “MyController”.