Add force based on rotation of another object?

So, I have a built a gun in unity and I have it set up to fire a rocket. The rocket is coming from a point at the end of the gun’s model. My issue is, when the weapon is rotated, the projectile doesn’t go the direction the gun is facing. Here is my code:

Code for the gun itself:

#pragma strict
var laser:GameObject;

public var rocketPrefab : Rigidbody;


function Update () {
if (Input.GetButtonDown("Fire1")){
var rocketInstance : Rigidbody;
Instantiate(laser,GameObject.Find("EmitterEnd").transform.position, Quaternion.Euler(0,0,0));
}}

Code for the projectile:

#pragma strict

function Start () {

}

function Update () {
rigidbody.AddForce(Vector3.forward*10);
}

Thanks in advance for your help!

That’s because you’re using Vector3.forward which is forward in relation to the world.
Try using transform.forward, which will move forward relative to the object the script is attached to.

Also you should probably change this:

Instantiate(laser,GameObject.Find("EmitterEnd").transform.position, Quaternion.Euler(0,0,0));

To this

Instantiate(laser,GameObject.Find("EmitterEnd").transform.position, transform.rotation);

Which should give the bullet the same rotation as the gun.