I’ve successfully managed to make the character move and face the direction of movement, but the moment the character stops moving, they rotate back to facing one direction of the z axis. I’ve looked around, but can’t see where I’m going wrong! Here’s my script
public class Movement : MonoBehaviour {
public float speed;
public float rotationspeed;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float horizontalInput = Input.GetAxisRaw("Horizontal");
float verticalInput = Input.GetAxisRaw("Vertical");
Vector3 movementDirection = new Vector3(horizontalInput, 0, verticalInput);
movementDirection.Normalize();
transform.Translate(movementDirection*speed*Time.deltaTime,Space.World);
if (movementDirection != Vector3.zero);
{
Quaternion toRotation = Quaternion.LookRotation(movementDirection, Vector3.up);
transform.rotation = Quaternion.RotateTowards(transform.rotation, toRotation, rotationspeed + Time.deltaTime);
}
}
}