I use this code that I already found on the forum. It works correctly, but it does not go through the identity axis. Instead of the shortcut through this axis, it goes around it by the longest path in the opposite direction.
Any ideas on how to fix this?
public static float3 EstimateAnglesBetween(quaternion from, quaternion to)
{
float3 fromImag = new float3(from.value.x, from.value.y, from.value.z);
float3 toImag = new float3(to.value.x, to.value.y, to.value.z);
float3 angle = math.cross(fromImag, toImag);
angle -= to.value.w * fromImag;
angle += from.value.w * toImag;
angle += angle;
return math.dot(toImag, fromImag) < 0 ? -angle : angle;
}
......
var desiredAngularVelocity = EstimateAnglesBetween(curRot, desiredRotation);
var angularFinal = desiredAngularVelocity * unscaledDt;
physicsVelocity.SetAngularVelocityWorldSpace(physicsMass, rotation, angularFinal);
......