Shoot Script

Does anyone know how to write a script that will let you shoot?
I already have one but am looking for one that doesn’t transform the prefab “forward” as it won’t work if the player looks up.
Thankyou so much in advance.

var projectilePrefab : GameObject;
var fp1 : GameObject;
var fireRate : float = 1;
var nextFire : float = 1;

function Update ()
 {

       if( Input.GetButton("Fire1") && Time.time > nextFire)
       {
         nextFire = Time.time + fireRate;
         Instantiate(projectilePrefab, fp1.transform.position, fp1.transform.rotation);

       }
}

This would go on my characters gun and in the scene I would create an empty gameobject that would be a child under the gun. The empty gameObject would be placed at the end of my gun mesh(so where the bullet would come out). In the Inspector on the gun I would assign all the correct parts to the variable slots(for example the projectile mesh to the “projectilePrefab” and so on). Then on the projectile mesh I would go to Component>Phsyics>Rigidbody to add a rigidbody(if you want to you can mess with the rigidbody’s parameters) because you need a rigidBody to use a constant force. Then go to Component>Phsyics>ConstantForce (then mess with the “relative force” parameter until when you fire your projectile it goes straight out from the gun). The empty gameobject’s (the firepoint’s) axis is what direction the projectile will go off of so look at the way it is facing for the right axis to change in the constant force.

But that that extent of my knowledge on this. Hopefully you will be able to look at my script example and be able to change yours so it works properly.