hello, I´m new here and i´m just starting to learn Unity.
I¨m making a script to make my character turns around to the dirrection it is moving but my problem is that the character doesn´t stay facing in the same direction when it stops moving.
When i test it I get the message in the console “Look rotation viewing is zero”. i tried to fix it by adding “0.001f” in the “vector 3 MoveDir” right next to “inputvector.x” but it doesn´t work, the problem is still there. And I´m not really sure how to fix it.
Here is the script that I made:
public class Playercontrolerscript : MonoBehaviour
{
[SerializeField] private float MoveSpeed = 7f;
private void Update()
{
Vector2 InputVector = new(0, 0);
if (Input.GetKey(KeyCode.W))
{
InputVector.y = +1;
}
if (Input.GetKey(KeyCode.S))
{
InputVector.y = -1;
}
if (Input.GetKey(KeyCode.A))
{
InputVector.x = -1;
}
if (Input.GetKey(KeyCode.D))
{
InputVector.x = +1;
}
InputVector = InputVector.normalized;
Vector3 MoveDir = new(InputVector.x, 0f, InputVector.y);
transform.position += MoveSpeed * Time.deltaTime * MoveDir;
float rotatespeed = 10f;
transform.forward = Vector3.Slerp(transform.forward, MoveDir, Time.deltaTime * rotatespeed);
}
}