Hello, all
I am working on getting a gun to work, I have the cloning working, but now my bullet isn’t moving, I am using this code:
var Bullet = pc.createScript('bullet');
Bullet.attributes.add('bullet',{type:'entity'})
Bullet.attributes.add('speed',{type:'number'})
// initialize code called once per entity
// initialize code called once per entity
Bullet.prototype.initialize = function () {
this.entity.collision.on('collisionstart', this.onCollisionStart, this);
this.entity.collision.on('collisionend', this.onCollisionEnd, this);
if(this.entity.enabled === true){
this.entity.setRotation(this.bullet.getRotation());
};
};
// update code called every frame
Bullet.prototype.update = function (dt) {
if(this.entity.enabled === true){
this.entity.translateLocal(this.speed,0,0);
};
};
Bullet.prototype.onCollisionStart = function (result) {
if (result.other.tags.has('player' || 'sb')) {
this.entity.destroy();
}};
// uncomment the swap method to enable hot-reloading for this script
// update the method body to copy state from the old instance
// Bullet.prototype.swap = function(old) { };
// learn more about scripting here:
// https://developer.playcanvas.com/user-manual/scripting/
All the attributes are defined, so I don’t know what’s wrong. I am grateful for any help!
Editor: PlayCanvas | HTML5 Game Engine
Gun entity is called “R1” and the bullet is a child of R1.