# Help! Child rotation, negate offset of parent rotation?

Hello.
I’ve got a little issue here, that I’ve been trying to tackle for weeks.

I have a turret, on a ship, that I need to rotate to face a direction in World Space.
However, to do so I need to offset the rotation of it’s parent.

How can I do that?

I attempted to get the offset like this:

``````quaternion worldForwards = new quaternion(0, 0, 0, 1f);
quaternion offset = math.mul(worldForwards, parentQuaternionRotation);
``````

However, it’s rotations are not correct when applied to the final quaternion ( see below )

Here is my code in pure form. float3 is synonymous with Vector3 in Unity.Mathematics

``````float3 targetDirection = math.normalize(targeting.relativeTargetPosition);
float3 up = parentLocalToWorld.localToWorld.Up;
quaternion parentRotation = parentLocalToWorld.localToWorld.Rotation;
quaternion thisRotation = localToWorld.Rotation;

quaternion final = quaternion.LookRotation(targetDirection, up); // Rotation must respect parent up axis.

rotation.Value = final; // final will be offset by parentLocalToWorld.rotation, need to negate.
``````

Not an answer but so you know, there are dedicated DOTS sub-forums here that might help you better.

I can always move your post there if you wish.

Hello Melv, thanks I’d appreciate it if you would.
Though, this isn’t specifically a DOTS issue. It’s just Quaternion math. Was hoping someone could teach me.

If I follow you correctly, maybe adapting this would help. Get your child world-space rotation and the inverse of the parent world-space rotation and combine or mul them together.

In short above, the “parentQuaternionRotation” needs to be the inverse (Transform.worldToLocal) or “public static float4x4 inverse(float4x4 m)”

NOTE: Unity.Mathematics has “public static quaternion inverse(quaternion q)” for this inversion.

Thank you very much! That’s very helpful.

1 Like

Hey @Lapsapnow , or anyone for that matter. I am attempting to do something similar and cannot seem to follow. Did you end up figuring this out? And could you elaborate?