# Rapid Fire?

**URL:** <https://forums.unrealengine.com/t/rapid-fire/70471>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [August 2, 2016, 11:15am UTC](https://forums.unrealengine.com/t/rapid-fire/70471 "2016-08-02T11:15:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_b87c07691](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b87c07691](https://forums.unrealengine.com/u/anonymous_user_b87c07691)\
**Post date:** [August 2, 2016, 11:15am UTC](https://forums.unrealengine.com/t/rapid-fire/70471/1 "2016-08-02T11:15:16Z")

</div>

Hello, I want to make player continuously fire if I hold left mouse click. What I’ve made is I updated character’s tick function so it counts deltatime, and when it gets to “deltatime \* 20”, only then OnFire() function gets called, if player is still holding left mouse click. Then the variable resets to zero and again counts to deltatime \* 20. Is there more rational decision? Because I suppose deltatime is different for every player (Im planning to do multi-player) and the rate can be rather different.

---

<div class="post-metadata">

**Author:** ![Pionwave](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Pionwave](https://forums.unrealengine.com/u/Pionwave)\
**Post date:** [August 3, 2016, 12:41am UTC](https://forums.unrealengine.com/t/rapid-fire/70471/2 "2016-08-03T00:41:51Z")

</div>

> **[Gameplay Timers](https://docs.unrealengine.com/4.27/en-US/ProgrammingAndScripting/ProgrammingWithCPP/UnrealArchitecture/Timers/)**
>
> Timer construct for performing actions at set intervals

OnPressed - fire once and set the timer to your delay between shots - referencing your actors Fire() function

OnReleased - clear the timer delegate

---

<div class="post-metadata">

**Author:** ![anon19956301](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anon19956301](https://forums.unrealengine.com/u/anon19956301)\
**Post date:** [August 3, 2016, 2:41pm UTC](https://forums.unrealengine.com/t/rapid-fire/70471/3 "2016-08-03T14:41:15Z")

</div>

Another way would be, to have three variables: bool Firing, float Delay (set in editor), float LastShotTime

OnPressed - set firing to True.  
OnTick - If firing and CurrentTime \> (LastShotTime + Delay) THEN fire and LastShotTime = CurrentTime  
OnReleased - set firing to False.

---

<div class="post-metadata">

**Author:** ![ugmoe](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ugmoe](https://forums.unrealengine.com/u/ugmoe)\
**Post date:** [March 16, 2020, 7:00am UTC](https://forums.unrealengine.com/t/rapid-fire/70471/5 "2020-03-16T07:00:13Z")

</div>

i found a nice way to do rapid fire :

 ![Capture.PNG](https://d3kjluh73b9h9o.cloudfront.net/original/3X/2/4/24ad48be479459e0ac106e3ccee5050c0362390d.png)
