Ok so my solution involves removing the bullet entity and instead relying on raycasting using the gun scripts.
Here is the single auto:
var Singleauto = pc.createScript('singleauto');
// THE DELAY BETWEEN SHOTS BEFORE THE PLAYER CAN FIRE AGAIN IN SECONDS, IN BURST MODE THIS IS THE TIME BETWEEN BURSTS
Singleauto.attributes.add("thedelay", {
type: "number",
default: 1
});
// INHERENT INACCURACY WHEN NOT AIMING
Singleauto.attributes.add("inaccuracy", {
type: "number",
default: 10
});
// ACCURACY WHEN AIMING, USUALLY LEAVE THIS AT ZERO UNLESS YOU ARE DOING WEIRD STUFF
Singleauto.attributes.add("accuracy", {
type: "number",
default: 0
});
// CHECKS IF THE GUN IS BURST FIRE
Singleauto.attributes.add("isburst", {
type: "boolean",
});
// TIME BETWEEN BULLETS IN SINGLE BURST IN SECONDS. ONLY ACTIVE IF ISBURST IS TRUE
Singleauto.attributes.add("burstdelayS", {
type: "number",
});
// TIME BETWEEN BULLETS IN SINGLE BURST IN RPM. ONLY ACTIVE IF ISBURST IS TRUE
Singleauto.attributes.add("burstdelayRPM", {
type: "number",
});
// NUMBER OF BULLETS IN BURST. ONLY ACTIVE IF ISBURST IS TRUE
Singleauto.attributes.add("burstnumber", {
type: "number",
});
// ENEMY TAG IT DAMAGES
Singleauto.attributes.add("enemyTag", {
type: "string",
default: "enemy"
});
// BULLET MAX RANGE
Singleauto.attributes.add("range", {
type: "number",
default: 10000
});
Singleauto.prototype.initialize = function() {
this.timer = 0;
this.currentburst = 1;
this.canburst = false;
};
Singleauto.prototype.update = function(dt) {
// ONLY USED FOR BURST. REMEMBER THAT SECONDS TAKES PRIORITY OVER RPM, SO IF RPM IS TO BE USED SECONDS MUST BE AT ZERO. WHAT THIS FUNCTION ACTUALLY DOES HERE IS CONVERT THE RPM TO SECONDS, WHICH IS WHAT THE SCRIPT ACTUALLY USES
if (this.burstdelayS === 0) {
Realrate = (1 / (this.burstdelayRPM / 60))
} else {
Realrate = this.burstdelayS
}
// THREE DEBUG FUNCTIONS BELOW CAN BE REMOVED. MESSED UP BY BURST MODE BUT THIS IS ONLY DEBUG INFO SO WHO CARES.
FirerateinS = this.thedelay
FirerateinRPM = Math.round(60 / this.thedelay)
Firemode = "SINGLE AUTO"
// CHECKS IF PLAYER IS AIMING AND ACCURACY IS ADJUSTED
if (this.app.mouse.isPressed(pc.MOUSEBUTTON_RIGHT)) {
this.entity.setLocalEulerAngles((Math.random() * this.accuracy) - (this.accuracy / 2), (Math.random() * this.accuracy) - (this.accuracy / 2), (Math.random() * this.accuracy) - (this.accuracy / 2));
} else {
this.entity.setLocalEulerAngles((Math.random() * this.inaccuracy) - (this.inaccuracy / 2), (Math.random() * this.inaccuracy) - (this.inaccuracy / 2), (Math.random() * this.inaccuracy) - (this.inaccuracy / 2));
}
this.timer += dt;
// CHECKS TO MAKE SURE BULLETS IS MORE THAN ZERO, THAT LEFT CLICK IS CLICKED, AND IF THE TIMER IS GREATER THAN THE DELAY
if (Bullets > 0) {
if (this.app.mouse.wasPressed(pc.MOUSEBUTTON_LEFT)) {
if (this.timer > this.thedelay) {
anglePos = this.entity.getLocalEulerAngles().clone();
anglePos.mulScalar(this.range);
from = this.entity.getPosition();
result = this.app.systems.rigidbody.raycastFirst(from,anglePos);
if(result){
if(result.entity.tags.has(this.enemyTag) {
result.entity.translateLocal(0,-50000);
result.sound.play("sound");
Grams += 1;
};
};
this.entity.sound.play("sound");
this.timer = 0;
Bullets -= 1;
Missing += 1;
Recoilburst = 1;
this.canburst = true;
//this.currentburst += 1;
}
}
// BURSTS GUN ONLY IF ISBURST IS TRUE
if (this.isburst === true) {
if (this.currentburst < this.burstnumber) {
if (this.canburst === true) {
if (this.timer > Realrate) {
anglePos = this.entity.getLocalEulerAngles().clone();
anglePos.mulScalar(this.range);
from = this.entity.getPosition();
result = this.app.systems.rigidbody.raycastFirst(from,anglePos);
if(result){
if(result.entity.tags.has(this.enemyTag) {
result.entity.translateLocal(0,-50000);
result.sound.play("sound");
Grams += 1;
};
};
this.entity.sound.play("sound");
this.timer = 0;
Bullets -= 1;
Missing += 1;
Recoilburst = 1;
this.currentburst += 1;
}
}
}
}
}
if (this.currentburst === this.burstnumber) {
this.currentburst = 1;
this.canburst = false;
} else if (Bullets === 0) {
this.currentburst = 1;
this.canburst = false;
}
};
And the full auto
var Fullauto = pc.createScript('fullauto');
// REMEMBER THAT THIS SCRIPT IS ATTACHED TO THE BULLET PARENT ENTITY
// THIS IS THE FIRE RATE IN SECONDS. LEAVE AT ZERO IF YOU WANT TO USE RPM
Fullauto.attributes.add("firerateS", {
type: "number",
default: 0
});
// THIS IS THE FIRE RATE IN ROUNDS PER MINUTE
Fullauto.attributes.add("firerateRPM", {
type: "number",
default: 0.1
});
// INHERENT INACCURACY WHEN NOT AIMING
Fullauto.attributes.add("inaccuracy", {
type: "number",
default: 10
});
// ACCURACY WHEN AIMING, USUALLY LEAVE THIS AT ZERO UNLESS YOU ARE DOING WEIRD STUFF
Fullauto.attributes.add("accuracy", {
type: "number",
default: 0
});
// TAG OF THE ENEMY
Fullauto.attributes.add("enemyTag", {
type:"string",
default:"enemy"
});
// BULLET MAX RANGE
Fullauto.attributes.add("range", {
type:"number",
default:"10000"
});
Fullauto.prototype.initialize = function() {
this.timer = 0;
};
Fullauto.prototype.update = function(dt) {
// REMEMBER THAT SECONDS TAKES PRIORITY OVER RPM, SO IF RPM IS TO BE USED SECONDS MUST BE AT ZERO. WHAT THIS FUNCTION ACTUALLY DOES HERE IS CONVERT THE RPM TO SECONDS, WHICH IS WHAT THE SCRIPT ACTUALLY USES
if (this.firerateS === 0) {
Realrate = (1 / (this.firerateRPM / 60))
} else {
Realrate = this.firerateS
}
// THREE DEBUG FUNCTIONS BELOW CAN BE REMOVED
FirerateinS = Realrate
FirerateinRPM = Math.round(60 / Realrate)
Firemode = "FULL AUTO"
// CHECKS IF PLAYER IS AIMING AND ACCURACY IS ADJUSTED
if (this.app.mouse.isPressed(pc.MOUSEBUTTON_RIGHT)) {
this.entity.setLocalEulerAngles((Math.random() * this.accuracy) - (this.accuracy / 2), (Math.random() * this.accuracy) - (this.accuracy / 2), (Math.random() * this.accuracy) - (this.accuracy / 2));
} else {
this.entity.setLocalEulerAngles((Math.random() * this.inaccuracy) - (this.inaccuracy / 2), (Math.random() * this.inaccuracy) - (this.inaccuracy / 2), (Math.random() * this.inaccuracy) - (this.inaccuracy / 2));
}
this.timer += dt;
// CHECKS TO MAKE SURE BULLETS IS MORE THAN ZERO, THAT LEFT CLICK IS CLICKED, AND IF THE TIMER IS GREATER THAN THE FIRERATE REQUIREMENT
if (Bullets > 0) {
if (this.app.mouse.isPressed(pc.MOUSEBUTTON_LEFT)) {
if (this.timer > Realrate) {
anglePos = this.entity.getLocalEulerAngles().clone();
anglePos.mulScalar(this.range);
from = this.entity.getPosition();
result = this.app.systems.rigidbody.raycastFirst(from,anglePos);
if(result){
if(result.entity.tags.has(this.enemyTag) {
result.entity.translateLocal(0,-50000);
result.sound.play("sound");
Grams += 1;
};
};
this.entity.sound.play("sound");
this.timer = 0;
Bullets -= 1;
Missing += 1;
Recoilburst = 1;
}
}
}
};
These scripts should work, but are untested. If you get any errors please inform me.