my rocket fires in the wrong direction

here's my rocket launcher code:

var projectile : Rigidbody;
var initialSpeed = 20.0;
var reloadTime = 0.5;
var ammoCount = 20;
private var lastShot = -10.0;

function Fire () {
    // Did the time exceed the reload time?
    if (Time.time > reloadTime + lastShot && ammoCount > 0) {
        // create a new projectile, use the same position and rotation as the Launcher.
        var instantiatedProjectile : Rigidbody = Instantiate (projectile, transform.position, transform.rotation);

        // Give it an initial forward velocity. The direction is along the z-axis of the missile launcher's transform.
        instantiatedProjectile.velocity = transform.TransformDirection(Vector3 (0, 0, initialSpeed));

        // Ignore collisions between the missile and the character controller
        Physics.IgnoreCollision(instantiatedProjectile.collider, transform.root.collider);

        lastShot = Time.time;
        ammoCount--;
    }
}

and here's my rocket code:

// The reference to the explosion prefab
var explosion : GameObject;
var timeOut = 3.0;

// Kill the rocket after a while automatically
function Start () {
    Invoke("Kill", timeOut);
}

function OnCollisionEnter (collision : Collision) {
    // Instantiate explosion at the impact point and rotate the explosion
    // so that the y-axis faces along the surface normal
    var contact : ContactPoint = collision.contacts[0];
    var rotation = Quaternion.FromToRotation(Vector3.up, contact.normal);
    Instantiate (explosion, contact.point, rotation);

    // And kill our selves
    Kill ();    
}

function Kill () {
    // Stop emitting particles in any children
    var emitter : ParticleEmitter= GetComponentInChildren(ParticleEmitter);
    if (emitter)
        emitter.emit = false;

    // Detach children - We do this to detach the trail rendererer which should be set up to auto destruct
    transform.DetachChildren();

    // Destroy the projectile
    Destroy(gameObject);
}

@script RequireComponent (Rigidbody)

so basically what happens is that the rocket fires in the wrong direction and more towards me

It appears that the orientation of whatever the script is attached to isn't right...for example, if u have a spawn point at the end of the rocket launcher it is probably rotated the wrong way. Instead of pointing away from you, it is pointing more toward you. Or a situation similar to that.

The code seems to be right (Though personally i'd use = transform.forward * initialSpeed; for the velocity just because it's a little easier to read - I aways get Transform Direction and InverseTransformDirection mixed up).

The only thing I can think of is that the forward vector of the missile launcher isn't pointing in the right direction

there are many things that may be creating this problem, the one that seems most likely is you may have your player backwards in local vs global space or something like that. making your initialSpeed var = -20 should do the trick.

there are many things that may be creating this problem, the one that seems most likely is you may have your player backwards in local vs global space or something like that. making your initialSpeed var = -20 should do the trick.