Help with my Character Controller

Hey, I am struggling to find a way to make the player rotate to its current direction. For example if I press the down arrow, the player would face the camera and walk towards it. Or if I pressed right the player would face and walk right. Here is my current script :

    var speed : float = 6.0;
	var jumpSpeed : float = 8.0;
	var gravity : float = 20.0;

	private var moveDirection : Vector3 =;

	function Update() {
		var controller : CharacterController = GetComponent(CharacterController);
		if (controller.isGrounded) {
			moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
			moveDirection = transform.TransformDirection(moveDirection);
			moveDirection *= speed;
			if (Input.GetButton ("Jump")) {
				moveDirection.y = jumpSpeed;
		moveDirection.y -= gravity * Time.deltaTime;
		controller.Move(moveDirection * Time.deltaTime);

I have tried many methods but simply can’t find a way to do it, any help would be appreciated.

So if I am understanding your context correctly then you are simply wanting the transform.forward to become equal to either Vector3.forward, Vector3.back, Vector3.left, or Vector3.right depending on if the player has pressed 1, or 4 buttons, and probably not blending these together (if you do want to blend then then things get a little harder), and then move the character in that direction.

essentially I am seeing:

if(Input.GetAxis("Vertical") < 0){
    transform.forward = Vector3.back;
}else if(Input.GetAxis("Vertical") > 0){
    transform.forward = Vector3.forward;
}else if(Input.GetAxis("Horizontal") < 0){
    transform.forward = Vector3.left;
}else if(Input.GetAxis("Horizontal") > 0){
    transform.forward = Vector3.right;
moveDirection = transform.forward;
// do gravity work here
controller.Move(moveDirection * Time.deltaTime); // I would suggest adding in some multiplication factor because Time.deltaTime is usually rather small (somewhere between .01, and maxTimestep)

the next suggestion would be to store the transform so that you don’t have to keep looking it up for performance