Topdown Zelda-esque character controller help c#

I’m trying to have a fixed topdown camera that does not rotate with the character, which is what I want, but I can’t get the character to rotate without rotating the character controller too. That would be bad, as then the character wouldn’t move relative to the camera, which is what I’m trying to accomplish. Transform.Rotate doesn’t do anything, and trying to modify the value of transform.rotation returns one of several errors. I’m at my wits end; how do I get the character to face the direction they’re moving relative to the camera?

The Legend of Zelda: A Link Between Worlds-style Controller Unity C#
works really cool with a xbox controller thumbstick. didn´t test it with playstation controller…

using UnityEngine;

[RequireComponent(typeof(CharacterController))]
public class LinkController : MonoBehaviour
{
    public float RunSpeed = 9;

    // public float JumpSpeed = 9;
    public float TurnSpeed = 25f;
public float Gravity = 20;
    public float ThumbStickDeadZone = 0.1f;

    // [HideInInspector]
    public float Speed = 0;

    [HideInInspector]
    public Vector3 MoveDirection = Vector3.zero;

    [HideInInspector]
    public Transform Transform;

    [HideInInspector]
    public CharacterController Controller;

    public float X = 0f;
    public float Y = 0f;

    public virtual void Awake()
    {
        Controller = GetComponent<CharacterController>();
        Transform = transform;
    }

    public virtual void Update()
    {
        X = Input.GetAxis("Horizontal");
        Y = Input.GetAxis("Vertical");
    }

    public virtual void FixedUpdate()
    {
        Move(X, Y);
    }

    public void SetSpeed(float rs, float ts)
    {
        RunSpeed = rs;
        TurnSpeed = ts;
    }

    public void Move(float h, float v)
    {
        Speed = 0;
        MoveDirection.y -= Gravity * Time.deltaTime;
        if (Mathf.Abs(v) > ThumbStickDeadZone || (Mathf.Abs(h) > ThumbStickDeadZone))
        {
            var lookRotation = new Vector3();
            lookRotation.Set(h, 0, v);
            lookRotation = lookRotation.normalized;

            var rotation = Quaternion.LookRotation(lookRotation, Vector3.up);
            if (lookRotation.magnitude > ThumbStickDeadZone)
            {
                Speed = RunSpeed;
                transform.rotation = Quaternion.Slerp(Transform.rotation, rotation, Time.deltaTime * TurnSpeed);
            }
        }
        if (Controller.isGrounded)
        {
            MoveDirection = Transform.TransformDirection(Vector3.forward).normalized;
            MoveDirection *= Speed * Time.deltaTime;
            //if (Input.GetButton("Fire1"))
            //      MovementProperties.MoveDirection.y = JumpSpeed;
        }
        Controller.Move(MoveDirection);
    }
}

Maybe you are attempting something similar to what I’m doing in this little project:

http://azrapse.es/windofthewest/

Move the character with WASD and rotate the camera with Q and E. The character movement depends of the direction the camera is looking at. So for example, D always moves character to the right in the screen.

For doing that, I have the character being followed by the camera with a script that updates the camera position every frame.
The input is controlled in this way:

  • Get the front direction and right direction of the camera, projected over the flat 2D floor. This sounds harder that it is. Just make a

    Vector2 cameraForward = new Vector2(camera.forward.x, camera.forward.z);
    Vector2 cameraRight = new Vector2(camera.right.x, camera.right.z);

With those two, you have the 2D direction ‘Up’ and ‘Right’ should move the character object. The directions for ‘Down’ and ‘Left’ are just the negative of those vectors.

To make the character move, I do something like this:

var movement = new Vector3(Input.GetAxis(horizontalAxisName)*cameraRight, 0, Input.GetAxis(verticalAxisName)*cameraForward);

And then I move the character by that amount.
For the character model to face the direction of the movement, you can do it manually by rotating the character model depending on the movement.

Thanks for your help. I got something working pretty well. Here’s the code for anyone interested:

using UnityEngine;
using System.Collections;

public class CharacterMovement : MonoBehaviour {

//Variables
public GameObject player;
public float turnspeed=180f;
public float speed = 6.0F;
public float jumpSpeed = 8.0F; 
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;


void Update() {
    CharacterController controller = GetComponent<CharacterController>();
    // is the controller on the ground?
    if (controller.isGrounded) {
        //Feed moveDirection with input.
        moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
        moveDirection = transform.TransformDirection(moveDirection);
        //Multiply it by speed.
        moveDirection *= speed;
        //Jumping
		if (moveDirection != Vector3.zero){
			if(Vector3.Angle (transform.forward, moveDirection) > 179){
				moveDirection = transform.TransformDirection (new Vector3(.01f, 0, -1));
			}
			player.transform.rotation = Quaternion.RotateTowards(player.transform.rotation, Quaternion.LookRotation (moveDirection), turnspeed * Time.deltaTime);
		}
        if (Input.GetButton("Jump"))
            moveDirection.y = jumpSpeed;
    }
    //Applying gravity to the controller
    moveDirection.y -= gravity * Time.deltaTime;
    //Making the character move
    controller.Move(moveDirection * speed * Time.deltaTime);
}

}