Search Unity

How do you detect which foot in a walk cycle is currently off ground

Discussion in 'Animation' started by grossimatte, Jun 7, 2018.

  1. grossimatte

    grossimatte

    Joined:
    Mar 15, 2013
    Posts:
    43
    Hello everyone,
    i have a looping walk cycle, and a Walk_stop_rightfoot and walk_stop_leftfoot animations.

    How do i detect which foot is currently off the ground at the moment the input magnitude is below a certain threshold?

    The goal is to have the character naturally stopping with the same foot that was ahead in the animation cycle at the moment the player wanted to stop the character.

    I was thinking of using Animation Events in the walk cycle, so that "RightFoot" or "LeftFoot" would be passed to the bools in my Mecanim animation controller.

    Or is there a better method?

    Thanks for your help!
     
  2. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    theANMATOR2b likes this.
  3. grossimatte

    grossimatte

    Joined:
    Mar 15, 2013
    Posts:
    43
  4. IanItor

    IanItor

    Joined:
    Dec 21, 2017
    Posts:
    12
    Radivarig likes this.
  5. Amaron77

    Amaron77

    Joined:
    Jun 16, 2018
    Posts:
    17
    I am also having the same problem of pivotWeight returning 0.5. I know this is an old thread but the question is very relevant to me at the moment and I can't find any info via searching. If anyone has some info I'd very much appreciate the help. Thank you.
     
  6. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    you are probably using a generic rig rather than a humanoid rig
     
  7. qaswarzeeshan

    qaswarzeeshan

    Joined:
    Jul 18, 2019
    Posts:
    2
    I am having the same Issue always return 0.5 and Rigs are set to Humanoid and animations are also set to humanoid! I am using Unity 2018.4.2
     
  8. Amaron77

    Amaron77

    Joined:
    Jun 16, 2018
    Posts:
    17
    I could never get this to work either. I ended up using Animator.GetBoneTransform() with HumanBodyBones to determine which foot was in the air.

    You can also set the animation controller to have an IK pass and use OnAnimatorIK to check the foot position.
    Code (CSharp):
    1.      
    2. private void OnAnimatorIK(int layerIndex) {
    3.    Vector3 leftFootT = animator.GetIKPosition(AvatarIKGoal.LeftFoot);
    4.    Quaternion leftFootQ = animator.GetIKRotation(AvatarIKGoal.LeftFoot);
    5.  
    6.    Vector3 leftFootH = new Vector3(0, -animator.leftFeetBottomHeight, 0);
    7.    Vector3 leftFootPos = leftFootT + leftFootQ * leftFootH;
    8. }
    I still really want to know why I can't get pivotWeight to work though.
     
    pizzaboy13, Lipoly and qaswarzeeshan like this.
  9. papathor

    papathor

    Joined:
    Oct 8, 2012
    Posts:
    41
    Just want to add that I'm also always getting 0.5 for a Humanoid character's pivotWeight as well, on 2019.3.
     
  10. BroVodo

    BroVodo

    Joined:
    Oct 2, 2012
    Posts:
    52