I have tried looking all over the internet for a fix and have spent a long time trying to fix the problem myself, so before you say look it up, I have. My problem is that the bullet I instantiate is not going forward, but to the right or at a 45 degree angle up from where it is supposed to shoot from. I want the bullet to shoot straight forward, but I cannot figure out how to do this. I have created an empty gameobject at the end of my gun and instantiate from there. Here is my script:
#pragma strict
var Barrel : Transform;
var BarrelPos : Transform;
var Bullet1 : GameObject;
function Update () {
if (Input.GetKey(KeyCode.LeftArrow)){
Barrel.Rotate(Vector3.back, Space.Self);
}
if (Input.GetKey(KeyCode.RightArrow)){
Barrel.Rotate(Vector3.forward, Space.Self);
}
if (Input.GetKeyDown(KeyCode.Space)){
var Bullet = Instantiate(Bullet1, BarrelPos.position, BarrelPos.rotation) as GameObject;
Bullet.GetComponent.<Rigidbody>().AddForce(BarrelPos.position * 1000);
}
}
Thanks in advance for help!