I want to make it so the body and head all look at the player with different weights.
However, because execution is arbitrary, they all occur out of order, causing things to look too far.
What are some methods to avoid this? The only methods I can think of all require adding stuff outside of the script.
Usually that’s all done by a single script/function which has a handle on all of the bones involved, and it’s not necessarily simple to figure out how each bone should be rotated.
Are you doing this on a rigged model? Probably the easiest thing would be to use Animator.SetLookAtPosition along with Animator.SetLookAtWeight, but that assumes your model is in a certain format:
Not really. At least, not if you’re just going to be using Transform.LookAt. You need for each of the “bones” in the chain rotates only a portion of the total required to get the tail to be looking at the right place. As @PraetorBlue mentioned, there’s a name for that: Inverse Kinematics. It’s not a trivial thing to write on your own. There are plenty of packages on the asset store that offer this, but Unity also has some limited, built-in IK for some cases.
What does your model look like? Does it have a formal Rig?
The body sections and the head are all individually looking at the target. So if the target is above the character,
the lower body would face the target 10%, the chest rotates about 25%, and the head rotates 100%. This also means that if something is right in front of the character, they will essentially lean back while looking at it.
However because each section needs to individually look, they must be done in order, otherwise the head might rotate first, and then the chest, which causes the head to look the wrong way.
But still, not quite, unless these are all completely independently, non-nested objects. Usually, the Chest will be a child object of the body, and the head will be a child object of the chest. So if you rotate the lower body by 10%, that implicitly rotates the chest and head by that amount, since they’re child objects. So if you apply 100% of the rotation to the head, it would be over-rotated when you consider the rotation it inherits from the parent objects. IK solvers are designed to account for the cumulative rotation. But maybe by “100%” you mean 100% of the rest of the way. In any case, I don’t think LookAt works with partial amounts, so you’d end up needing to do some semi-complicated rotation logic to get a rotation that rotates a partial amount, based on the weight, between two rotations.
Again, what does your model look like? Do you have an Animator on it? Can you just use the built-in IK to set SetLookAtPosition on the animator, to avoid having to reinvent the wheel?
I mean 25% as in weight.
0% would be rotation from parent bone, 100% would be looking directly at target 50% is halfway.
If lookat functions were all run in order from root to head, then they would not stack.
There is nothing special about the model, it is just a basic human body structure.