@Marstheplanet Can you describe what is going wrong with your project? Is it that you are getting errors or does the script not do what you want it to do? There have been several topics related to this on the forum. Some could take a better look if you shared your project.
Hi thank you for the reply! The problem is the bullet is not moving and just floating in one area. I need to spawn and shoot. I did try following the other threads and I’m still having a hard time.
@Marstheplanet Does your bullet have a collision and rigid body? Also, in the rigid body you will need to set the rigid body to Dynamic. I am not sure about the force applied above.
Shoot.prototype.shoot = function(dt){
// Clone the bullet as specified by the attribute
var bullet = this.bullet.clone();
// Add it to the game
this.app.root.addChild(bullet);
var player = this.entity;
// Its force is in the direction the player is facing
this.force = new pc.Vec3();
this.force.copy(player.forward);
this.force.scale(this.power);
var pos = player.getPosition();
var direction = player.forward;
// Add it a little further if the player is already going fast
//pos.add(direction.scale(5 + player.rigidbody.linearVelocity.length() * 0.01));
bullet.setPosition( pos );
var bulletRotation = player.getRotation();
bullet.setRotation( bulletRotation );
bullet.rotateLocal(90,0,0);
bullet.enabled = true; //Must enable after setting position!
bullet.rigidbody.applyImpulse(this.force);
};
Here is some code from something that I have done. Maybe it will apply. THE ROTATION ABOVE MAY NEED ADJUSTING>