Search Unity

Set humanoid avatar pose to it's last frame of various animations instantly

Discussion in 'Animation' started by Cazforshort, Sep 2, 2022.

  1. Cazforshort

    Cazforshort

    Joined:
    Feb 22, 2016
    Posts:
    16
    Hello,

    I have an issue involving a dynamically scalable avatar and several dozen animations.

    The issue is that I need to create a list of the positions of each hand at the last frame of each animation.
    This needs to be done at runtime since the avatar's height changes with a scale slider, so just going to the frame on the animation scrubber and checking the position won't do.

    I thought I would be able to use the following script, but the results are all off by a lot.

    Code (CSharp):
    1. IEnumerator addTargetPositionToList(){
    2.  
    3.         Ghost.enabled = true;
    4.         for (int i = 0; i < states.Count; i++) // 12 states
    5.         {
    6.             animator.SetBool("PlayingAnimation", true);
    7.  
    8.             // set animation to last frame
    9.             animator.CrossFade(states[i], -0f,0 , 1);
    10.  
    11.  
    12.             yield return new WaitForSeconds(0.1f);
    13.  
    14.             // append the target positions to the array. 24 positions total
    15.             leftHandTargets.Add(leftHand.position);
    16.             rightHandTargets.Add(rightHand.position);
    17.         }
    18.  
    19.  
    20.     }
    Is there a convenient way to get the last state of an animation? CrossFade just isn't working well.