Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Get Hand Position and rotation while doing IK

Discussion in 'Animation' started by libra34567, Feb 6, 2018.

  1. libra34567

    libra34567

    Joined:
    Apr 5, 2014
    Posts:
    62
    So I have a character that is in water, with a floating animation. While floating i asked it to perform a IK movement so his right arm would grab the ladder while the rest of the body is floating.

    I problem comes when I want to access the position of his hand with HandObj.position while he is doing IK. But unity seems to give me the position and rotation of his hand as if he's arm is doing Animation (Which he is not).

    So how should i get his hand's position and rotation while he's arm is doing IK movement?

    Any suggestions would be appreciated. Thank you.
     
  2. StickyHoneybuns

    StickyHoneybuns

    Joined:
    Jan 16, 2018
    Posts:
    207
    There are two ways I can think of. First is this a humanoid you made yourself? If so you should have a bone on that specific hand. I would simply do a handPos = bone.transform.position. You can just add the bone as a public gameobject in the inspector. If for some reason you don't have a bone on that hand you can add an empty gameObect child and position it at the hand location then do the same as above for position.

    Also, what is HandObj? Is the name of the hand? If so you should be using HandObj.transform.position.
    Posting some could would help as well.
     
  3. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    This is a little bit beyond my knowledge base - but Ill throw out a suggestion that might help.
    Maybe you are attempting to capture the hand position before the IK has processed? If you attempt to capture the hand position after IK has processed - in LateUpdate do you still get the incorrect hand position?
     
  4. libra34567

    libra34567

    Joined:
    Apr 5, 2014
    Posts:
    62
    @StickyHoneybuns @theANMATOR2b

    Thank you guys for your suggestions, both helpful
    I seems to figure out the problem, I tested to access hand's in ik position in AnimatorIK, both before and after i set IK weight and target. Both give me the same result, it returns the position of hand as if It's animating.

    Then i put it under lateupdate, it worked. Unity seems to apply IK after AnimatorIK is called, instead of after SetIKTarget is called, the ik movement is in between OnAnimatorIK and LateUpdate, so yea, access it in lateupdate it is!
     
    theANMATOR2b likes this.
  5. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Glad you solved.
    This might be helpful, though I only confused myself when looking at it in relation to IK.
    https://docs.unity3d.com/Manual/ExecutionOrder.html

    It would be nice if the documentation was more specific about stuff like this - if it isn't already and I'm just not digging deep enough.
     
  6. libra34567

    libra34567

    Joined:
    Apr 5, 2014
    Posts:
    62
    Indead, i couldn't find the internal animation execution order anywhere