Need Help with Relative Rotations

Hello,

I’ve been trying to get this to work all day. Any help is appreciated. I need to get game object B’s rotation values as relative to object As rotation values (the user controls B).

I have another set of objects (C and D) placed elsewhere in world space (position and rotation wise). I want D to rotate relative to C’s rotation just as B rotates relative to A. I got help doing something similar in the past with position instead of rotations using inverse transform points.

So I’m basically looking for the rotational equivalent of the below code.

Binverse = A.InverseTransformPoint (B.position);
D.position = C.TransformPoint (Binverse);

Thank you!

You need Quaternion.Inverse:

This gives the opposite rotation of a things rotation. If you multiply B’s rotation by the inverse of A’s rotation, you get B relative to A.

It’d be like saying B - A, but in quaternion math.

The order is important. So it’d be:

var rotFromAToB = Quaternion.Inverse(A.rotation) * B.rotation;

Note that if you multiply this result onto A, you get B.

var b = A.rotation * rotFromAToB; //b should be nearly the same as B.rotation, giving some minor float error
1 Like

Thank you very much! I believe this gets me half way. How would I then implement the second part - make D rotate around C using “rotFromAToB” values? Thanks again.

D.rotation = C.rotation * rotFromAToB;
1 Like

THANK YOU!