I am trying to make a game object face my mouse, rotating only on the y axis. However my object only rotates 90 degrees, then when my mouse goes past 90 degrees, the object just rotates in reverse 90 degrees. It’s hard to explain, so here is my code.
//Rotate
Vector3 mouseWorldPosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, 0, Input.mousePosition.z));
Vector3 dir = transform.position - mouseWorldPosition;
dir.y = 0;
Quaternion rot = Quaternion.LookRotation (dir);
rot *= Quaternion.Euler (0, 180, 0);
transform.rotation = Quaternion.Slerp (transform.rotation, rot, rotationSpeed * Time.deltaTime);
Sorry if it’s formatted incorrectly.