Rotation problem.

How do I subtract one rotation from another?

This is my problem: I have a head and torso both looking at the mouse point in 3d but since the only way I could get it to work was to make the spine mimic the head rotation. So since the head is connected to the spine, it rotates a bit extra and thus does not look at the target/mouse point correctly.

So how would I go about doing this? Subtracting the final head rotation by the spine rotation?

I am using the mecanim headlook at.

This is where my spine turns according to head:

LateUpdate(){

spinebone.localrotation = headbone.localrotation;

// … and this is the mecanim code for the head look:

anim.SetLookAtPosition(ahit.point);
                lookWeight = Mathf.Lerp(lookWeight, 1f, Time.deltaTime*lookSmoother);

  }

So yeah I need to get the head to minus a few degrees whilst turning to look to compensate for the extra turn thanks to the torso turning underneath.

Hope you can help… Please.

It might not be the most efficient but you should first check if you’re looking left or right. Because one direction will be subtracting and one direction will be adding just due to the fact you’re in 3D space.

From there you can just simply get the x, y, z of each and add/subtract a amount or percentage of an amount.

    Quaternion rotation;
    rotation = new Quaternion(spinebone.localRotation.x - 2, spinebone.localRotation.y - 2, spinebone.localRotation.z - 2, spinebone.localRotation.w);
    spinebone.localRotation = rotation;

Obviously the value 2 is probably not what you’re after, I would make it a percent of your current number that way it doesn’t look “fake”. You want it to vary in its rotation.