Hi guys,
I have an object in my scene which receives certain values from another script, and these values are rotation angles for the object (rotation of object around Y axis). So, if a value 180 or 270 is passed, the object has to rotate 180 or 270 is the same direction.
I implemented this for requirement in the following way and this works to some extent as well:
IEnumerator RotateObject(Transform thisTransform, Vector3 endDegrees, float time){
Quaternion startQuat = transform.rotation;
Quaternion endQuat = transform.rotation * Quaternion.Euler (endDegrees);
float rate = 1.0f / time;
float t = 0.0f;
while (t < 1.0) {
t += Time.deltaTime * rate;
transform.rotation = Quaternion.Slerp(startQuat, endQuat, t);
yield return 0;
}
}
However, the problem here is that the Quaternion.Slerp actually takes the shortest path to the target rotation and hence my rotation slerping doesn’t always happen in the same direction. How do I rectify this here?
Thanks a lot for the help.