Search Unity

Question Animation Rigging, Foot IK

Discussion in 'Animation' started by ColtPtrHun, Jul 26, 2020.

  1. ColtPtrHun

    ColtPtrHun

    Joined:
    Nov 20, 2019
    Posts:
    9
    Hi everyone!

    I would like to create a automated Foot IK for my game.
    My plan is to override my animations using the Two Bones IK Constraint component from the Animation Rigging package for each leg.

    The difficulty for setting this up is to select - or more like to create - a Target object for the end of the IK chain.
    The idea is to take the position of the leg bone, and then go up a bit, and then Raycast back down, so it would look like something like this:

    Code (CSharp):
    1. Ray ray = new Ray((footLeft.transform.position + 0.5f * Vector3.up), Vector3.down);
    2. RaycastHit rayHit;
    3.  
    4. if (Physics.Raycast(ray, out rayHit, 0.5f, 1 << LayerMask.NameToLayer("Environment")))
    5. {
    6.        footLeftTarget.transform.position = rayHit.point;
    7. }
    8. else
    9. {
    10.        footLeftTarget.transform.position = footLeft.transform.position;
    11. }
    12.  
    The problem with this, is that the position of the footLeft bone will be already constrained, and I need the original position, which is the result of the original animation.

    So my question is, is there a way to access to the original transform of a bone?
    -Peter
     
  2. ColtPtrHun

    ColtPtrHun

    Joined:
    Nov 20, 2019
    Posts:
    9
    I ended up not using the Animation Rigging package for the Foot IK at all.
    For my problem the Animator.SetIKPosition function is what I needed.

    As its description says: "Unity can calculate how to move the part toward the target from the starting point (ie, the current position and rotation obtained from the animation)."