Character Controller Rotation

So, in my game, I created a character, and I want to use “Character controller” to move it. It is moving fine, but I can’t rotate it. Actually, I am being able to rotate it using transform.Translate, but that doesn’t affect the way I move my character with Character Controller, so it always moves foward, backward, left or right whithout taking in consideration it’s roation. Basicly, even though I rotate the character around, it move around as if it wasn’t rotating. Sorry if this is an obvious and stupid question, but I am very new to Unity and scripting. Thanks!

You should not move with Translate, since collisions are not detected - you should use CharacterController.Move instead.

This is a simple script that I’ve adapted from the CharacterController.Move example to rotate instead of just go right and left. It’s very simple, and you can modify it easily if you want to add new features:

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

private var moveDirection : Vector3 = Vector3.zero;
private var controller: CharacterController;

function Start(){
    controller : CharacterController = GetComponent(CharacterController);
}

function Update() {
    var turn: float = Input.GetAxis("Horizontal");
    transform.Rotate(0, turn * turnSpeed * Time.deltaTime, 0);
    if (controller.isGrounded) {
        moveDirection = transform.forward * Input.GetAxis("Vertical") * speed;
        if (Input.GetButton ("Jump")) {
            moveDirection.y = jumpSpeed;
        }
    }
    // Apply gravity
    moveDirection.y -= gravity * Time.deltaTime;
    // Move the controller
    controller.Move(moveDirection * Time.deltaTime);
}

Ok this post is realy old, but I found a solution to rotate your character Controller with translate!


All you need to do is to rotate your object with translate:

transform.eulerAngles = new Vector3(0, yourRotation, 0);

and Apply to your Move direction the “new Transformed Direction” with:

moveDirection = transform.TransformDirection(moveDirection);

at the end you apply the moveDirection to your Character controller:

controller.Move(moveDirection * Time.deltaTime);

You should make sure you’re passing Space.self as the second argument to transform.Translate, otherwise the object will move in world space, regardless of rotation.

Always remember there are two coordinate systems to deal with: Global and Local.

Global axis directions never change, but local axis directions change with rotation.

Also this is NOT working:

transform.rotation.SetLookRotation(moveDirection);

Insted use like this:

Quaternion rot = new Quaternion();
rot.SetLookRotation(moveDirection);
transform.rotation = rot;