Ammo script lacking movement

Hi all.

I’ve been playing around with this ammo script and it’s working good (well most of it) except the shooting direction. When I’m facing straight forward sometimes it shoots left, right it’s tweaky. Can’t really get one direction. Cannot face only one way, or for example when looking down it shoots sometimes on the side sometimes up sometimes in the ground.

var speed = 3.0; 
var rotateSpeed = 3.0; 
var bullitPrefab:Transform;
var currentBullets = 15;//This is the amount RIGHT NOW that the gun has. (should be 0 by default.)
var totalBullets = 15; //TOTAL amount the gun will have
var bulletsDisplayed : GUIText;

function Update () 

{ 

    
   // Move? forward / backward 
   var forward = transform.TransformDirection(Vector3.forward); 
   var curSpeed = speed * Input.GetAxis ("Vertical"); 
    
   if(Input.GetButtonDown("Fire1")) 
    
      { 
if (currentBullets > 0) //only shoot if you have ammo.
{
      var bullit = Instantiate(bullitPrefab, GameObject.Find("Main Camera").transform.position,Quaternion.identity);
    
            bullit.rigidbody.AddForce(transform.forward * 3500); 

currentBullets--; //subtract one
}
else //if you have less than 1 bullet
{
//perform reload animation
 currentBullets = totalBullets; //reset ammo count
}

      } 
	  bulletsDisplayed.text = "Current amount of bullets is " + currentBullets;

}

What might be the problem? Thanks.

First of all, what object is creating the bullets? In your code it looks like you are spawning the bullets at the position of the Main Camera but setting the bullet rotation back to (0, 0, 0).

It was a a cube object but then changed it to the main camera. Does that mean that the rotation of the camera is mixed with the given position (0,0,0) ?

Quaternion.identity sets the object’s rotation to Vector3(0, 0, 0). You should use transform.rotation instead.

Thanks it worked. One more question, what positions does Quaternion.identity take? I suppose that this transform.rotation is taking the characters rotation.