thx also my bullet script wont work
var Bullet = pc.createScript('Bullet');
// initialize code called once per entity
Bullet.prototype.initialize = function() {
if(this.entity.enabled){
this.entity.sound.play("pistol shooting sound effect");
}
//Registriert die Kugel eine Kollision, verschwindet sie 3 Sekunden später
this.entity.collision.on('collisionstart', this.onCollisionStart, this);
};
// update code called every frame
Bullet.prototype.update = function(dt) {
//Davor war "enabled" bei der Kugel deaktiviert, da es ansonsten Probleme mit der Kollision mit dem Spieler gegeben hätte
if (this.entity.enabled === true) {
//Die Kugel wird korrekt ausgerichtet, damit sie von der Kamera aus "geradeaus" geschossen wird
this.impulse = new pc.Vec3();
this.impulse.copy(this.entity.forward).scale();
this.entity.rigidbody.applyImpulse(this.impulse);
//Selbstzerstörungstimer
setTimeout(function(){
this.entity.destroy();
}.bind(this), 7500);
}
};
//Verkürzter Selbstzerstörungstimer, falls die Kugel eine Kollision erkennt
Bullet.prototype.onCollisionStart = function (result) {
if (result.other) {
setTimeout(function(){
this.entity.destroy();
}.bind(this), 3000); }
};
var BulletGun = pc.createScript('bulletGun');
// initialize code called once per entity
BulletGun.prototype.initialize = function() {
};
// update code called every frame
BulletGun.prototype.update = function(dt) {
};
// swap method called for script hot-reloading
// inherit your script state here
// BulletGun.prototype.swap = function(old) { };
// to learn more about script anatomy, please read:
// https://developer.playcanvas.com/en/user-manual/scripting/
What’s the exact problem you are having? Are you seeing any error?
I see your BulletGun script is empty, meaning that you haven’t implemented that yet. Most likely that’s the problem now?
hey so iv done sum stuff with the scripts and added the bullet but it still wont fire
Try sharing your project so we can take a look then.
i did attach it tho wtf
it still doesnt work
The bullet entity has a static rigidbody. Based on the script this should be a dynamic rigidbody.
still wont work
Is the rotation of the bullet entity correct?
yeah
I don’t think so.
Apart from that I see you are missing a scale value in your script.
This:
this.impulse.copy(this.entity.forward).scale();
Should be something like this:
this.impulse.copy(this.entity.forward).scale(10);
I see you changed the script.
If you want to use translateLocal
you need to use a kinematic rigidbody.
i just put it to kinematic and where do i put this.impulse.copy(this.entity.forward).scale(10);
im new to JS sorry
With your current script you don’t use this anymore.
It looks like you changed the script name or something. Please parse the script.
If you get a warning sign after parsing you need to remove the script and add it again.
Or you didn’t save the script at all. You can use CTRL + S
to save the script.
i parsed it