So I am trying to make a burst gun but I have no clue how to code it. I already have some code for a semi and auto fire gun but just don’t know where to start with burst Help.
What I am trying to do is for the gun to fire 3 shots and then delay a sec.
Kind of like this…
This is the code I am building apon…
if(this.app.mouse.wasPressed(pc.MOUSEBUTTON_LEFT) && this.canShoot === true && this.burst)
{
this.particleSys.particlesystem.reset();
this.particleSys.particlesystem.play();
this.particleSys.particlesystem.reset();
if(result)
{
result.entity.collision.entity.rigidbody.applyImpulse(this.camera.forward.scale(this.hitImpulse), result.normal);
this.currentAmmo -= 3;
}else
{
return;
}
if(result.entity.name == 'Bean Boi')
{
result.entity.script.target.TakeDamage(this.damage);
}
}
can anybody help me plz…
Hi @Connor_Briggs! What is the problem you have with the code above? Or is that where you want to apply the delay?
The delay is the problem I have.
I have tried using the time-out thing in the forum below…
but i just could not get it to work using that.
I would use a counter because you want to do 3 shots in a row. I would also create a shoot function that you can call again after a small delay until 3 shots are fired. Something like below. (You can not copy and paste this code, it’s only to give you an idea of my logic).
// initialize function
this.counter = 0;
// update function
// mouse pressed and burst is enabled
if (this.counter == 0) {
this.burst();
}
Script.prototype.burst = function(){
// shoot
this.counter += 1;
if (this.counter != 3) {
setTimeout(function(){
this.burst();
}.bind(this), 1000);
}
else {
this.counter = 0;
}
};
thx for the help…
i’ll try that idea and see if i can get it to work.
1 Like