How would i implement weapon Firerate

this is my shooting script

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

GunShoot.prototype.update = function(dt) {
       var app =;
this.pistol ='pistol');
   if( {
    this.magsizeP = 12;     
   if ('pistol').enabled === true) {
       // shooting code 
        if ( {
            // shoot
            if (this.magsizeP !== 0) {
                var bullet ='bulletP').clone();
                bullet.enabled = true;
                // update magazine
                this.magsizeP = this.magsizeP - 1;

and can i add recoil?

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.


2 posts were split to a new topic: How to add FPS camera recoil

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

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

1 Like