0
\$\begingroup\$

I have recently been exploring Unity's inverse kinematics, to further polish the interaction between our rigged avatars and props.

Straight Arm

I have made a sample project, using PuppetMaster's basic humanoid for the model, rig, and idle animation, but without Final IK; meaning this is Unity's inverse kinematics. Inside our OnAnimatorIK method, we set the right elbow's SetIKHintPosition and SetIKHintPositionWeight like we did with the hand IK:

animator.SetIKHintPosition(avatarIKHint, hintPosition);
animator.SetIKHintPositionWeight(avatarIKHint, hintBlendValue);

animator.SetIKPosition(sourceIKGoal, targetPosition);
animator.SetIKPositionWeight(sourceIKGoal, blendValue);

You can see the left and right hand correctly move to where we set it. However, it seems like the right elbow is ignoring the hint position entirely. You can see the white debug line connecting the elbow to the hint position in the picture above.

It seems like the elbow ONLY bends if it absolutely must for the hand to reach the target position, regardless of where the hint is set, and the weight value given.

I have fiddled with this on and off for days and still haven't found a solution. Others have asked the same question here and on other sites, but no one has posted an answer.

\$\endgroup\$
0
\$\begingroup\$

I notice that the AvatarIKHint enumeration supports applying hints to only the elbows and knees.

This suggests to me that Unity uses a simple 2-bone IK solution for this case. That means it thinks of the shoulder or hip joint as fixed, and finds the best solution it can using only the upper arm & forearm bones, or thigh and shin bones for legs.

The advantage of this approach is it's fast: you can find the best solution in a single step with a little high school trigonometry, without having to iterate over longer bone chains and converge gradually toward a solution.

Now, a 2-bone IK system with a root point (shoulder / hip) and a target point has one extra degree of freedom: the rotation about the line from the root to the target. Imagine doing the arm-flapping motion of the chicken dance: the line from your shoulder to your wrist stays fixed, as does the joint angle at your elbow; all that changes is the rotation at your shoulder to position your elbow low/tucked-in close to your body or raised outward. All of these poses are potential, equally-valid solutions for this IK problem, so if we care which of these poses we adopt, then we need to hint the solver in the desired direction.

It looks like that degree of freedom is what these hint methods serve to control. So for instance if your FPS character was putting their elbow way out to the side like a novice when holding their weapon, you could use a hint to guide the elbow down to a more professional-looking tucked-in position.

Once the arm or leg is fully extended however, there's no extra degree of freedom left: the elbow/knee has to sit along the line from the shoulder/hip to the wrist/ankle. Putting the elbow anywhere else would make the end effector deviate from the target (bad) or distort the skeleton (also bad).

So, it looks like what you're trying to accomplish with this hint is not what this hint is made to do. What you should do instead depends on what your ultimate aim is.

If you want the character to lean to the side, bringing the shoulder closer to give the elbow more room to bend & position itself away from the direct shoulder-to-target line, then you might have luck applying that lean as an additive animation layer.

\$\endgroup\$
  • \$\begingroup\$ Yes, they seem to use the term "hint" for elbows and knees and "target" for hands and feet. I simply presumed that meant that the hands and knees got priority, but I really don't know for certain. Their documentation for the hint methods don't say much at all. \$\endgroup\$ – Zoop Aug 18 '19 at 3:12
  • \$\begingroup\$ So what you're saying is that once the arm is straight, it will view any other orientation as too costly, and thus ignore the hints? But the avatar almost always straightens the arms immediately, unless you put it in a situation where it absolutely must bend to achieve the hand target. \$\endgroup\$ – Zoop Aug 18 '19 at 3:14
  • \$\begingroup\$ Long story short, it sounds like there is a 99% chance the elbow hints will never be used. It sounds kinda pointless to me then, if I understand your description. I have a hard time believing that this is true... \$\endgroup\$ – Zoop Aug 18 '19 at 3:15
  • \$\begingroup\$ If the arm has to be straight to reach the target (ie. the distance from shoulder to target is greater than or equal to the length of the upper arm plus the length of the forearm), then it's not that other elbow positions are too costly. It's that there is no other elbow position that allows the arm to reach the target. Try it: stand far enough from a door that you can just reach the knob with your arm straight. Now try to move your elbow somewhere else, without leaning your shoulder closer to compensate. You don't have that degree of freedom there — the hint is for poses where you do. \$\endgroup\$ – DMGregory Aug 18 '19 at 3:19
  • \$\begingroup\$ Can you arrange things so your target is closer to the shoulder, to give the arm more leeway to bend and make use of the hint you've set? \$\endgroup\$ – DMGregory Aug 18 '19 at 3:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.