Rotation problem with spawning bullet

I have had this problem a couple of times and i always forget how i fix it.What i am trying to do is make a bullet spawn in front of the barrel and add a force to move it forward and no matter what i do the bullet just moves to the left of the gun... Can someone please explain to me(EXPLAIN TO ME) how to fix this so i will always have a reference to solve this problem.

oh yea the code...

var bullettype : Transform;

var spawnspot : Transform;

var bulletspeed : float = 500.0;

function Update () {

if(Input.GetButtonUp("Fire1")){

var shot = Instantiate(bullettype,spawnspot.transform.position,spawnspot.transform.rotation);

shot.rigidbody.AddForce(transform.forward * bulletspeed);

Debug.Log("Fired");

}

What it sounds like is that, while you're spawning the bullet in at the spawnspot's position and rotation, spawnspot's transform might not be pointing in the correct direction in the first place; I'd check that first.

If that's not the case, try pausing the game directly after the bullet is spawned and seeing how it's axes differ from the spawnspot's transform - that should give you a better indication of what's off, relation-wise.

your bullet rotation is set to the rotation of spawnspot but you are adding force in the direction of the object this script is attached to. try spawnspot.transform.forward instead of transform.forward