[SOLVED] Bullet won't move

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.

Hi @Codeknight999!

Your script is probably not working because there are two scripts with the name bullet in your project.

Can you try the result with only one bullet script in your project?

You should not use collision for your bullet, as it can pass through objects without hitting

Thanks, that fixed it!

1 Like

I developed a system which visually appears like a translating object, but operates via raycasts. That way the bullet never goes through anything.