Search Unity

Question Is it possible to access the original hands position with Humanoid retargeting?

Discussion in 'Animation' started by 00christian00, Sep 2, 2020.

  1. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,035
    Just like the topic, is there any way to use MatchTarget to match the original hands position in the animation?
    Or is the only way to add an IK target for each hand?
    It would be handy to have it integrated in the body animation itself.
     
    customphase likes this.
  2. customphase

    customphase

    Joined:
    Aug 19, 2012
    Posts:
    246
    Have you found a solution to this? There are these red spheres gizmos that show up from animator, that look like its original positions of arms/elbows/feet/knees. So there should be a way to get those.

    upload_2021-2-3_20-48-14.png
     
  3. customphase

    customphase

    Joined:
    Aug 19, 2012
    Posts:
    246
    Ok, these red things are confirmed to be original positions of the limbs from the imported clip.

    https://forum.unity.com/threads/humanoid-rig-red-and-blue-spheres.503199/#post-3421800

    https://forum.unity.com/threads/humanoid-rig-red-and-blue-spheres.503199/#post-3506061

    And these are IK targets, so you can get them with GetIKPosition/Rotation.

    You would think its not useful cause the minute you use SetIKPosition/Rotation, the IK targets would get overwritten, and GetIKPosition/Rotation would instead return the values you set. But for some reason its not the way it works, GetIKPosition/Rotation always return the original limb values, which is great for us. So if you want your hands to IK-match hands from the imported animation, just use this script (dont forget to enable IK pass on specific layers in animator controller):

    Code (CSharp):
    1. public class AnimatorHandsIKMatchOriginal : MonoBehaviour
    2. {
    3.     public Animator anim;
    4.  
    5.     // Update is called once per frame
    6.     void OnAnimatorIK(int layerIndex)
    7.     {
    8.         anim.SetIKPosition(AvatarIKGoal.LeftHand, anim.GetIKPosition(AvatarIKGoal.LeftHand));
    9.         anim.SetIKPosition(AvatarIKGoal.RightHand, anim.GetIKPosition(AvatarIKGoal.RightHand));
    10.         anim.SetIKRotation(AvatarIKGoal.LeftHand, anim.GetIKRotation(AvatarIKGoal.LeftHand));
    11.         anim.SetIKRotation(AvatarIKGoal.RightHand, anim.GetIKRotation(AvatarIKGoal.RightHand));
    12.  
    13.         anim.SetIKPositionWeight(AvatarIKGoal.LeftHand, 1);
    14.         anim.SetIKPositionWeight(AvatarIKGoal.RightHand, 1);
    15.         anim.SetIKRotationWeight(AvatarIKGoal.LeftHand, 1);
    16.         anim.SetIKRotationWeight(AvatarIKGoal.RightHand, 1);
    17.     }
    18. }
     
    00christian00 likes this.
  4. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,035
    Thanks a lot, I will try it later. I need it for some acrobatic moves where the different body builds makes the hands go through walls and floors right now, didn't want to use collision just for this.