Hey, we’re making a FPS game but we have a problem with our shooting mechanism. Everytime we shoot, no bullet comes out. We’ve tried everything and are desperate! If you help we will be eternally grateful to you! BTW, the gunshot sound works but the bullet doesn’t work.
Shooting part of FPS script:
FirstPersonMovement.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;
var gun = this.app.root.findByName('gun');
// Its force is in the direction the player is facing
this.force = new pc.Vec3();
this.force.copy(gun.forward);
this.force.scale(this.gunpower);
var pos = gun.getPosition();
var direction = gun.forward;
// Add it a little further if the player is already going fast
// pos.add(direction.scale(5 + gun.rigidbody.linearVelocity.length() * 0.01));
bullet.setPosition( pos );
// try to get bullet to face forward
bullet.setLocalEulerAngles(0, 0, 0);
// 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);
//reduce ammo by 1
this.app.ammo--;
this.entity.sound.play('gunshot');
// destroy cloned bullet after 4 seconds
setTimeout(function(){
bullet.destroy();
}, 4000);
};
Ask any questions and we will answer promptly!