Hi! I’m making an FPS game, but for some reason, my gun won’t shoot properly. It looks like it’s falling down on the ground, rather than shooting objects.
This is my code:
var ShootBulletScript = pc.createScript('shootBulletScript');
ShootBulletScript.attributes.add('bulletEmitter',{
type:'entity',
});
// initialize code called once per entity
ShootBulletScript.prototype.initialize = function() {
};
// update code called every frame
ShootBulletScript.prototype.update = function(dt) {
if (this.app.keyboard.wasPressed(pc.KEY_SPACE)) {
var bulletFromTheAsset = this.app.assets.get(137934526);
var bulletInstance = bulletFromTheAsset.resource.instantiate();
this.app.root.addChild(bulletInstance);
var bulletPosition = this.bulletEmitter.getPosition();
bulletInstance.rigidbody.teleport(bulletPosition);
this.force = new pc.Vec3();
this.force.copy(this.entity.forward);
this.force.copy(this.entity.forward).scale(800);
bulletInstance.rigidbody.applyForce(this.force);
}
};
This is my hierarchy for the gun:
Thank you!