# How do I spread a LookAt rotation over 3 bones with different percentages?

I'm trying to rebuild the RE4 controller.

At first, I thought that only the chest bone is used to rotate the pistol towards a target. I have then however found a hack to put the camera in a fixed position so that I could actually see the bone rotations.

Juding the logic that I have recorded, I believe that first a LookAt rotation is used, and then this rotation is spread over the abdomen, abdomen2 and chest bones.

Looking at the video that I have recorded, I think that the rotation is not "divided by 3", but procentually and then again changing towards the limits (for example, at the limits, the rotation is mostly done only by the chest).

Can anybody tell me if my judgement is correct, and if yes, how to split a rotation this way?

Would this be correct?

-->

The chest bone moves the most, the abdomen2 less, and the abdomen bone moves the least. In percentages:

• chest bone: 60%
• abdomen2 bone: 30%
• abdomen bone: 10%

Let's assume a rotation of 200°.

Am I right to assume that the rotation of each bone is calculated like this?

Chest bone: Gets 60% of 200°, that is 120°

Abdomen2 bone: Gets 30% of 200°, that is 60°

Abdomen bone: Gets 10% of 200°, that is 20°.

Thank you!

ps: Here are a few screenshots, but it's much easier to estimate from the video:

• We generally can't tell you what is right or wrong for an existing game - as we've mentioned before, only the developers who worked on that game can tell you that. I'd say this looks like the output of either additive animations or an IK solver, but if you find it easier to think of as blending rotations on each bone in script then you can try it that way. At the end of the day it's all similar math, just applied with different code paths. – DMGregory Sep 5 at 13:12
• @DMGregory Do you think that they made an aim high pose and an aim low pose and blend between them? – tmighty Sep 7 at 21:42
• Some games do that. Once again, we cannot tell you what this game did specifically. – DMGregory Sep 7 at 21:47
• @DMGregory I found a list of RE4 animations on a modder webpage, and there are a lot of "aiming gun", "aiming gun up", "aiming gun down", "aiming harpoon", "aiming harpoon up", "aiming harpoon down", etc . so I would tend to this that they did it this way in RE4. – tmighty Sep 10 at 20:59

You can blend between two orientations like so:

void PartlyRotateBone(Transform bone, Quaternion targetRotation, float strength) {
bone.rotation = Quaternion.Slerp(bone.rotation, targetRotation, strength);
}


Here, strength gives a linear blend from the bone's existing/animated rotation when it's zero, to the target rotation when it's 1, with even steps along the way.

You could also use Quaternion.Lerp, which is a little cheaper, but slightly non-uniform. The rotation gets biased toward the source for strength < 0.5f, and toward the target for strength > 0.5f, for a slight "ease in-out" curve that might even be desirable for your uses.

You can then construct and apply your rotation something a bit like this:

Quaternion targetRotation = Quaternion.LookRotation(lookDirection, lookUp);

PartlyRotateBone(abdomen, targetRotation, 0.1f);
PartlyRotateBone(abdomen2, targetRotation, 0.3f);
PartlyRotateBone(chest, targetRotation, 0.6f);


Be sure to work from the root of the armature toward the leaves - because each time you apply one of these rotations, you change the rotations of all downstream bones.

You should also factor that into the percentages you choose. Let's say my three bones are all in a straight stack, facing North, and my target rotation is 90 degrees East. Even if I choose the same strength of 0.5 for each bone, the top bone will twist more, because it inherits the twist of the bones below it:

• abdomen rotates halfway between its current (0 degrees North) to the target (90 degrees East), to face 45 degrees North-East

• abdomen2 rotates halfway between its current (45 degrees North-East) to the target (90 degrees East), to face 67.5 degrees East-by-North-East

• chest rotates halfway between its current (67.5 degrees East-by-North-East) to the target (90 degrees East), to face 78.75 degrees East-by-North-East.

You can use an AnimationCurve to choose your rotation strength values as a function of your target angle, which can help you shift which bones twist more or less aggressively at different angle ranges, in a smoothly continuous way.