Quaternion relative difference problem
I have some code that updates an objects euler angles based on a parent rotation and an old rotation. I have it currently working as intended using euler angles, but it suffers from gimbal lock, which is why I'm trying to convert the code to Quaternions. Here's the code:
newEuler = parentTransform.eulerAngles + (transform.eulerAngles - oldEuler); transform.eulerAngles = newEuler; oldEuler = parentTransform.eulerAngles;
Because I'm subtracting the oldEuler from the current rotation, then adding the parent rotation, I thought I could simply replace the code with this:
newRotation = parentTransform.rotation * (transform.rotation * Quaternion.Inverse(oldRotation)); transform.rotation = newRotation; oldRotation = parentTransform.rotation;
But this does not give the expected result at all. Any pointers here?