How to change my character's direction based on input?

Dear Pros, I have a simple question on how to change my character’s direction based on user input.

Although CharacterController.Move describes the sample code, however, I still do not know how to change my character’s direction. My expectation is: If user pressed left arrow key, my character will turn left then start moving towards left, if user pressed right arrow key, my character will turn right then start moving towards right.

The below sample CharacterController.Move code only describes how to move towards a direction but my character is always facing one direction. Help! Thanks a lot!

I’m having the same problem. Someone please help?

I’m not 100% sure if this would work, but try it anyway:

var moveDirection : Vector3;

function Update() {
moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
Input.GetAxis("Vertical"));
transform.rotation = Quaternion.LookRotation(movedirection);
}

It doesn’t work as a new script.
Do I place it in the CharacterController?
If so, where?

Just in your character controller script, for example FPSWalker.js. Since it already has the variable, moveDirection.

transform.rotation = Quaternion.LookRotation(moveDirection);