Help with CharacterController rotation

Hi I think this is an easy fix however I’m having trouble with it. Basically I need my CharacterController to face the same direction hes moving.

var speed : float = 4.0;
var gravity : float = 20.0;
private var velocity : Vector3 = Vector3.zero;
var controller : CharacterController;

function Update () 
{
	if (controller.isGrounded)
	{
		velocity = GetHorizontalMovement();
		velocity *= speed;
	}

velocity.y -= gravity * Time.deltaTime;
controller.Move (velocity * Time.deltaTime);
}

function GetHorizontalMovement()
{
var direction : Vector3 = Vector3 (Input.GetAxisRaw("Horizontal"), 0, 0);
return transform.TransformDirection (direction);
}

you can use (not tested)

function Update ()
{
   if (controller.isGrounded)
   {
      velocity = GetHorizontalMovement();
      velocity *= speed;
   }
 
   velocity.y -= gravity * Time.deltaTime;
   controller.Move (velocity * Time.deltaTime);
   if(Input.GetAxis("Horizontal") > 0)
      transform.rotation = Quaternion.Euler(0, 0, 0);
   else if(Input.GetAxis("Horizontal") < 0)
      transform.rotation = Quaternion.Euler(0, 180, 0);
}

You will need to adjust the rotating values sice I don’t know how your scene is set up.

E: I see you are a quiet new user, make sure to tick and vote answers that helped you on unity answers (also on your other questions) this helps others to see if an answer is sucessfully answered and the person you tick gets more karma :wink: