Rotate character towards direction?

Hi, Im trying to get a character to move and rotate towards the input received from a virtual joystick, I’ve got the movement working but I cant figure out how to make the character rotate in that direction. Here’s the code I’ve got so far:

// Setting up some basic variables
var speed : float = 2.0;
var rotationSpeed : float = 100.0;
var gravity:float = 500.0;

private var moveDirection:Vector3 = Vector3.zero;

// This var will request for a joystick input on the inspector
var JoystickScript:Joystick; 
// Displays the Jostick Pos on the inspector
var JoystickPos:Vector2;


function Update () 
{
	//Debug.Log(JoystickScript.position);
	// We take the position value from the Joystick script and turn it into a var called "JoystickPos"	
	JoystickPos = JoystickScript.position; 
	
	// Looks for the controller component
	var controller : CharacterController = GetComponent(CharacterController); 
	
	var translationY : float = JoystickPos.y;
	var translationX : float = JoystickPos.x;
	var rotationY : float = JoystickPos.y * rotationSpeed * Time.deltaTime;
	var rotationX : float = JoystickPos.x * rotationSpeed * Time.deltaTime;
	var rotation : float = JoystickPos.x * JoystickPos.y;
		
	// If the Joystick is moved then it plays the run animation
	if (controller.isGrounded && JoystickPos.y > 0.5 || JoystickPos.y < -0.5 || JoystickPos.x > 0.5 || JoystickPos.x < -0.5)
	{
	animation.CrossFade("RunF"); // Plays running animation
	moveDirection = Vector3(translationX, 0, translationY); // Allows player input
	moveDirection = transform.TransformDirection(moveDirection); // How to move
	moveDirection *= speed; // How fast to move
	//transform.Rotate (0, rotation, 0); // Rotates the character
	}	
	else
	{
	animation.CrossFade("Idle");
	moveDirection = Vector3(0, 0, 0); // Stops the character from moving when input is released
	moveDirection = transform.TransformDirection(moveDirection); // How to move
	moveDirection *= speed; // How fast to move
	}
	
	// Applies gravity
	moveDirection.y -= gravity*Time.deltaTime;
	
	// Moves the controller
	controller.Move(moveDirection * Time.deltaTime);
}

I think you could use the LookAt function by passing the player’s position plus the move direction.

transform.LookAt(transform.position + moveDirection);

Or, if that doesn’t work in your setup, you can calculate the angle using trig.

float rotation = Mathf.Atan2(moveDirection.z, moveDirection.x);

If the camera rotates with the player, this won’t work without additional consideration, specifically you would need to add the current rotation in. I mean if the camera is always following the player.