# How would i implement weapon Firerate

**URL:** <https://forum.playcanvas.com/t/how-would-i-implement-weapon-firerate/28223>\
**Category:** Help & Support\
**Created:** [November 3, 2022, 8:12pm UTC](https://forum.playcanvas.com/t/how-would-i-implement-weapon-firerate/28223 "2022-11-03T20:12:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thebosser\_24](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/thebosser_24/32/23506_2.png) [@Thebosser\_24](https://forum.playcanvas.com/u/Thebosser_24)\
**Post date:** [November 3, 2022, 8:12pm UTC](https://forum.playcanvas.com/t/how-would-i-implement-weapon-firerate/28223/1 "2022-11-03T20:12:31Z")

</div>

this is my shooting script

```javascript
var GunShoot = pc.createScript('gun');

GunShoot.prototype.update = function(dt) {
       
       var app = this.app;
this.pistol = this.app.root.findByName('pistol');
   if(this.app.keyboard.wasPressed(pc.KEY_R)) {
    this.magsizeP = 12;     
   }
   if (this.app.root.findByName('pistol').enabled === true) {
       // shooting code 
        if (this.app.mouse.isPressed(pc.MOUSEBUTTON_LEFT)) {
            // shoot
            if (this.magsizeP !== 0) {
                var bullet = this.app.root.findByName('bulletP').clone();
                this.app.root.addChild(bullet);
                bullet.reparent(this.app.root);
                bullet.setPosition(this.app.root.findByName('bulletP').getPosition());
                bullet.setRotation(this.app.root.findByName('bulletP').getRotation());
                bullet.enabled = true;
                console.log(bullet);
                // update magazine
                this.magsizeP = this.magsizeP - 1;
            }
        }
   }
};

```

and can i add recoil?

---

<div class="post-metadata">

**Author:** ![Leonidas](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/leonidas/32/6495_2.png) [@Leonidas](https://forum.playcanvas.com/u/Leonidas)\
**Post date:** [November 7, 2022, 9:54am UTC](https://forum.playcanvas.com/t/how-would-i-implement-weapon-firerate/28223/2 "2022-11-07T09:54:21Z")

</div>

Hi @Thebosser_24,

I don’t have an example in mind, but for fire rate you usually implement a cooldown timer. After each bullet fired you start a timer e.g. for 0.1 sec and in that period you don’t allow any more bullets to fire.

Do a forum search on how to add a timer in a PlayCanvas script.

For recoil you will need to move/animate your weapon between two threshold values. You can use PlayCanvas tween or lerping. It can be a bit advanced but do search on how to animate entities in the forum to get some good examples and get started.

Hope that helps.

---

<div class="post-metadata">

**Author:** ![yaustar](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/yaustar/32/2268_2.png) [@yaustar](https://forum.playcanvas.com/u/yaustar)\
**Post date:** [November 15, 2022, 6:25pm UTC](https://forum.playcanvas.com/t/how-would-i-implement-weapon-firerate/28223/3 "2022-11-15T18:25:58Z")

</div>

2 posts were split to a new topic: [How to add FPS camera recoil](https://forum.playcanvas.com/t/how-to-add-fps-camera-recoil/28395)

---

<div class="post-metadata">

**Author:** ![Thebosser\_24](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/thebosser_24/32/23506_2.png) [@Thebosser\_24](https://forum.playcanvas.com/u/Thebosser_24)\
**Post date:** [November 15, 2022, 4:11pm UTC](https://forum.playcanvas.com/t/how-would-i-implement-weapon-firerate/28223/4 "2022-11-15T16:11:41Z")

</div>

hello? its been a week. and its nearly been 2 weeks since I made this.

---

<div class="post-metadata">

**Author:** ![mvaligursky](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/mvaligursky/32/11681_2.png) [@mvaligursky](https://forum.playcanvas.com/u/mvaligursky)\
**Post date:** [November 15, 2022, 5:30pm UTC](https://forum.playcanvas.com/t/how-would-i-implement-weapon-firerate/28223/5 "2022-11-15T17:30:32Z")

</div>

Hi … have you tried the suggestions from @Leonidas ? They seemed very sensible to me.
