I’m making a character controller for a top down game, but after the character turns, when i let go of the movement keys, the rotation of the player goes back to 0 degrees on the y axis.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float speed;
[Range(0,1)]
public float turnSmoothing = 0f;
public Animator chestAnimator, waistAnimator;
public CharacterController controller;
float horizontal, vertical;
void Update()
{
horizontal = Input.GetAxis("Horizontal");
vertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(horizontal, 0, vertical);
controller.Move(movement.normalized * Time.deltaTime * speed);
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(movement), turnSmoothing);
if(horizontal != 0 || vertical != 0)
{
chestAnimator.SetBool("walking", true);
waistAnimator.SetBool("walking", true);
}
else
{
chestAnimator.SetBool("walking", false);
waistAnimator.SetBool("walking", false);
}
}
}