I am making a space game where I want the spaceship to shoot laser bullets. when I shoot the bullets they don’t fire straight out of the ship, but they fire at the same position relative to the scene. like this.
How can I make it shoot from the front of the ship and in the direction of the ship?
here is the code
#pragma strict
var bulletPrefab : Transform;
var player : GameObject;
var force : float = 2000;
var shootForce : float = 1000;
function Update () {
if(Input.GetMouseButtonDown(0)){
//fire bullet
fire();
//audio clip
}
}
function fire(){
var instanceBullet = Instantiate(bulletPrefab,transform.position,Quaternion.identity);
instanceBullet.rigidbody.AddForce(transform.forward*shootForce);
}
thanks