0
\$\begingroup\$

I came across this line of code below.
What the boolean "isMatchingTarget" is used for?

 private void OnAnimatorMove()
 {
   if(_animator.isMatchingTarget)
       _animator.ApplyBuiltinRootMotion();
 }
\$\endgroup\$
1

1 Answer 1

3
\$\begingroup\$

As the documentations says, this property tells you

If automatic matching is active.

OK, not very helpful, because it does not tell us what "automatic matching" actually is. But if we look at not just the scripting reference but at the regular Unity manual, we can find the article Target Matching which does explain the concept:

Often in games, a situation arises where a character must move in such a way that a hand or foot lands at a certain place at a certain time. For example, the character may need to jump across stepping stones or jump and grab an overhead beam.

You can use the Animator.MatchTarget function to handle this kind of situation.

In other words, you can use the script function animator.MatchTarget to tell the animator to move the animated object, so one of the characters limbs ends up interacting with a certain object in the environment (defined by position and rotation). The method animator.isMatchingTarget tells you whether or not this was done for the current animation.


By the way, there is also another way to make sure that character hands or feet (or gaze) end up exactly where you want them to be: Inverse Kinematics. The difference between target matching and IK is that target matching achieves that by translating and rotating the root of the gameObject, while IK adjusts the pose of the character to match.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .