Quaternion.Slerp rotating only 90 degrees.
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.
Answer by HonoraryBob · Mar 21, 2017 at 05:59 PM
@slushieboy99 I'm having a somewhat similar problem, except in my case I'm rotating an object toward a destination angle and then back again to the original rotation; but if the destination angle is roughly equal or greater than 90 degrees, it fails to rotate back again.
Your answer
Follow this Question
Related Questions
Ask some problem about rotation, quaternion and angle 0 Answers
Rotating to match surface normal (curved surface). 0 Answers
Quaternion does not work 0 Answers
How to convert User Values into degree(Angle)?? 2 Answers
Place Rows in Object automaticaly 0 Answers