In Unity, there is no built-in InverseTransformQuaternion method like Transform.InverseTransformPoint, but you can manually inverse transform a quaternion rotation from world space to local space using the inverse of the parent rotation.
If you have:
- A quaternion
worldRotation (rotation in world space)
- A
Transform called transform (the reference object you want to inverse-transform the rotation relative to)
Then, to convert worldRotation to the local rotation relative to transform, do this:
Quaternion localRotation = Quaternion.Inverse(transform.rotation) * worldRotation;
Quaternion worldRotation = transform.rotation * localRotation;
- Unity uses
Transform.rotation to represent world rotation.
- To transform a rotation into the local space of another object, you need to remove the reference object’s rotation — i.e., multiply by the inverse.
- This is analogous to how
Transform.InverseTransformPoint(worldPoint) works, but for orientation instead of position.
- World to Local:
local = Quaternion.Inverse(reference.rotation) * world;
- Local to World:
world = reference.rotation * local;
Let me know if you’re also rotating a direction vector or want the inverse transform relative to a parent/child relationship.