Convert rotation between local coordinate systems?

I have a rotated transform A that contains a nested rotated transform B. Now I’d like to retrieve B’s rotation relative to a third transform C which has it’s own rotation. In other words, I have two different frames of reference (local coordinate systems): A and C. I know B’s rotation relative to A because it’s a child of A, but I also need it’s rotation relative to C. Is there a quick and easy way to do this? Thanks!

1 Like

To convert between coordinate systems in unity use Transform.transformPoint and Transform.InverseTransformPoint. The idea behind that is to convert from A to global rotation and then from global to B.

1 Like

Is there an equivalent function for converting rotations instead of points?

1 Like
1 Like

You do the same, but with quaternion operations:

Quaternion wRot = localContainer.transform.rotation * myLocalRot;
Quaternion tgtSpaceRot = Quaternion.Inverse(tgtContainer.transform.rotation) * wRot;

First transform to worldspace, then from worldspace into the local space of the destination object.

Cheers

5 Likes