Transform.forward is always (0,0,1)

Hey guys, I'm trying to put together a Geometry Wars like clone just to become familiar with Unity. Currently I have an orthographic camera set up facing into the positive Z axis. I also have a cube, which is the player, moving around the screen and always rotating to face the mouse position.

Now, I've been trying to instantiate a bullet prefab in front of the player with a movement direction in the same direction the player is facing at the point of the instantiation. I've tried to simply Instantiate the prefab using...

Instantiate(bullet, transform.TransformPoint(transform.forward * 20, transform.rotation);

But Unfortunately, no matter how my cube is rotated transform.forward is always (0,0,1). And since my camera is orthogonal and facing into the positive Z axis, the bullet just appears right at the player position.

I have similar problems moving the actual bullet in the direction the player was facing at the time of instantiation. Doing...

transform.Translate( transform.forward * bulletSpeed * Time.deltaTime );

Has no effect either since transform.forward is (0,0,1) here as well.

So my question is, what should I be doing in order to get transform.forward to properly reflect the ships rotation. Or should I be using something else entirely?

Thanks!

Okay, so I (thinK) I've partially nailed down the issue. For one, I was doing my cube rotation incorrectly. Rather then using Transform.LookAt() I was calculating the angle between the mouse and cube manually using the arc tangent of the delta Y over delta X. But this actually was only rotating my cube 180 degrees, and then flipping it to go another 180. I hadn't noticed this issue because I had a solid color material on the cube, so any flipping wasn't visibly noticeable.

So I rewrote my rotate script to use LookAt() here it is:

// Update is called once per frame
void Update () {

    Vector3 mouseScreenPos = Input.mousePosition;
    Vector3 mouseWorldPos = Camera.main.ScreenToWorldPoint(mouseScreenPos);

    mouseWorldPos.z = transform.position.z;

    transform.LookAt(mouseWorldPos,Vector3.forward);            

}

And, the cube seems to be rotating a full 360 without flipping around in between.

So the Transform.forward variable seems to be working correctly, because if I instantiate like so:

Transform tempBullet;
Vector3 inFront = transform.rotation * (Vector3.forward * 1);           
tempBullet = (Transform)Instantiate
             (bulletBody,inFront + transform.position, new Quaternion(0,0,0,0) );

The bullet prefab correctly spawns in front of the player! So that's half of the issue now, my other issue is getting the bullet to actually move forward in the direction the player was facing when the bullet was fired.

I tried setting the forward vector of the bullet manually, like so:

Vector3 bulletForward = transform.rotation * (Vector3.right);   
tempBullet.forward = bulletForward;

But this produces inconsistent behavior depending on the direction of the player.

Can anyone point me in the right direction for my next hurdle, which is: How do a get a newly instantiated prefab to move in the direction of the player from the moment of instantiation?

Thanks.

EDIT:

So I fixed it by changing the bulletForward to be as so:

Vector3 bulletForward = transform.localRotation * new Vector3(0,1,1);

You just want `transform.forward`. `transform.TransformPoint()` is for converting local space to world space, which is pointless when you're using transform.forward to begin with.

Instantiate(bullet, transform.forward * 20, transform.rotation);