Character walks in the wrong direction, how can I rotate her 90 degrees or fix the issue?

I followed a tutorial (Rotating a Character in the Direction of Movement (Unity Tutorial) - YouTube) on how to make my character face the direction of movement. However, she never faces the direction, and editing her rotation on Unity doesn’t work when I use the controller. Any help is greatly appreciated, Im very new to coding.`using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{

public CharacterController controller;
private Vector3 direction;
public float speed = 8;
public float rotationSpeed;

private Animator animator;

void Start()
{
    controller = GetComponent<CharacterController>();
animator = GetComponent<Animator>();
}


void Update()
{
    float hInput= Input.GetAxis("Horizontal");
  float vInput= Input.GetAxis("Vertical");

//change direction
Vector3 movementDirection = new Vector3(hInput, 0, vInput);
movementDirection.Normalize();

transform.Translate(movementDirection * speed * UnityEngine.Time.deltaTime, Space.World);

if (movementDirection != Vector3.zero)
{
Quaternion toRotation = Quaternion.LookRotation(movementDirection, Vector3.up);

transform.rotation = Quaternion.RotateTowards(transform.rotation, toRotation, rotationSpeed * UnityEngine.Time.deltaTime);

}

//animating

animator.SetFloat(“speed”, Mathf.Abs(hInput));

direction.x = hInput * speed;
direction.z = vInput * speed;

controller.Move(direction * UnityEngine.Time.deltaTime);

}

}
`

Hi!

Changing the rotation of the character directly won’t do anything, because those values get overwritten by the movement script.

Instead you should try creating a child object and moving the art related components of your character onto it. This way you can give this child object a rotational offset which won’t be overwritten, and because it’s a child of the gameobject with the movement script, it will move along with it.

Hope this helps :slight_smile: