Hello - I am trying to make my character face the direction they are moving on a grid-based game. I have this code so far which doesn’t quite work.
private void Update()
{
//Face the direction the unit is moving
Vector3 dir = Vector3.zero;
transform.rotation = Quaternion.LookRotation(dir);
if (dir != Vector3.zero)
{
transform.rotation = Quaternion.Slerp(
transform.rotation,
Quaternion.LookRotation(dir),
Time.deltaTime * 1.0f
);
}
if (!Unit.isMoving)
{
anim.SetBool("IsMoving", false);
} else {
anim.Play("Walk");
anim.SetBool("IsMoving", true);
}
}
My thought was to try to find the velocity and then rotate based on that. What am I doing wrong?