Look rotation facing vector zero

My character keeps looking at vector zero when I use the following script, rather than the direction it's moving in. Any suggestions?

   if(charController.isGrounded == true)
        // Calculate the movement direction (forward motion)
        //Move in the direction based on the negative of the horizon axis
        moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
        transform.forward = moveDirection;

        ///Insert Jump here(Input.GetButton ("Jump")) 
        moveDirection.y = jumpSpeed;

    //Apply gravity every frame
    moveDirection.y -= gravity * Time.deltaTime;
    //Move using the direction and walkspeed multiplied by Time.deltaTime
    charController.Move(moveDirection * (Time.deltaTime * walkSpeed));


You need to use instead of "transform.foward = moveDirection":

if ( moveDirection != Vector3.zero ) 
  transform.rotation = Quaternion.LookRotation( moveDirection );

You can replace the .rotation = line with the one you have, but remember that you won't be able to directly control the up-vector as easily (LookRotation defaults to trying to align the object's +Y axis to the world's +Y axis)

You didn't tell him to look anywhere so he's not going to.

To do that you need to fiddle with the rotation property of the character.

It is stored in the transform.rotation.

For example rotation over Y axis 90 degrees would make your character face absolute right (not relative right).

If it's a 2D world like mario and you can only face absolute left and right Y -90 (or 270) or any increment or decrement of that with 360 (which is pointless but possible) will make your character face left or right.

In a 3D world however you need to do a lot more. So Please do tell what kind of world we're in.

I would have the character look at its own velocity. Then it always face the direction its moving. Like the `CameraRelativeController.js` in the Penelope tutorial.

function FaceMovementDirection()
    var horizontalVelocity : Vector3 = charCharacter.velocity;
    horizontalVelocity.y = 0; // Ignore vertical movement

    // If moving significantly in a new direction, point that character in that direction
    if ( horizontalVelocity.magnitude > 0.1 )
        transform.forward = horizontalVelocity.normalized;

P.S. I haven't really used this tutorial for much other than ideas for future projects so I really don't know how well this works, just that I picked it out as logical, and I don't know why Unity would steer you wrong.

1) Delete or comment out "transform.forward = moveDirection;" from the script

2) Add the Mouse Look script to your player game object from Component-->Camera Control-->Mouse Look

Vicenti's right; transform.forward is read-only and can be used to find out what direction an object is facing. By setting "moveDirection" and using CharacterController.Move() with that Vector3 value, you're doing all you need to.

Vicenti, you are a genious!