Modifying Move function to not take into account rotation

I’m trying to create a basic top-down RPG where you can move around, and the character rotates based on which direction you are moving (Like in top-down FF titles, Zelda, etc.).

However, I’m using a modified move script that I copied from the documentation, and when I make calls to the Move() function, the rotation modifies what the WASD keys do. That is, if I turn my character 180 degrees around so that it is facing downwards, every key is inverted.

Below is my moving script. How can I modify this so that the movement does not take into account rotation? I do want to use Move() because of the simple collision.

var speed : float = 4.0;
var gravity : float = 200.0;

private var moveDirection : Vector3 = Vector3.zero;

function Update() {
    var controller : CharacterController = GetComponent(CharacterController);
    var horizontal = Input.GetAxis("Horizontal");
    var vertical = Input.GetAxis("Vertical");

    moveDirection = Vector3(horizontal, 0, vertical);
    moveDirection = transform.TransformDirection(moveDirection);
    moveDirection *= speed;

    moveDirection.y -= gravity * Time.deltaTime;

    controller.Move(moveDirection * Time.deltaTime);
}

Thanks!

The solution is: Don’t rotate the CharacterController at all. You should add your visual character as a child object and keep the rotation of the parent fixed. You can freely rotate the child object with this setup.