I am encountering an issue when easing the rotation using Quaternions. The ease seems to work fine until one point in the rotation it decided to rotate 360 degrees to get from its start point to its end point. I am assuming it's because the value is going from x to -x. How can I account for or prevent this issue?
Here is my code
GameObject head;
float speed;
void Start () {
head = GameObject.Find("Camera (eye)");
speed = 1f;
}
void Update () {
transform.rotation = new Quaternion(EaseOutBack(transform.rotation.x, head.transform.rotation.x, Time.deltaTime * speed), EaseOutBack(transform.rotation.y, head.transform.rotation.y, Time.deltaTime * speed), EaseOutBack(transform.rotation.z, head.transform.rotation.z, Time.deltaTime * speed), EaseOutBack(transform.rotation.w, head.transform.rotation.w, Time.deltaTime * speed));
}
public static float EaseOutBack(float start, float end, float value)
{
float s = 1.70158f;
end -= start;
value = (value) - 1;
return end * ((value) * value * ((s + 1) * value + s) + 1) + start;
}
I would try slerping between two quaternions and apply the easing function to the t parameter of Quaternion.Slerp.
Something like:
transform.rotation = Quaternion.Slerp(transform.rotation, head.transform.rotation, EaseOutBack(0, 1, Time.deltaTime * speed));