Search Unity

Playing animation doesn't return the same end time value

Discussion in 'Animation' started by laurelhach, Nov 27, 2014.

  1. laurelhach

    laurelhach

    Joined:
    Dec 1, 2013
    Posts:
    229
    Hi Guys,

    Here is my problem,

    I have an animation I play on one of my character.
    I use the legacy option so I don't use mecanim or a translation using the root motion.

    I do a play on the animation and I rotate (or translate) my character during the same time.
    I use Quaternion.Slerp() or Vector3.Lerp() to move/rotate the character.
    In my while loop I debug the time of my animation state.

    This is an example :
    Code (csharp):
    1.  
    2. AnimationState anim = animation["Walk"];
    3. animation.Play("Walk");
    4. while(t < 1.0f){
    5.      // At the same time, I would move / rotate my character using Quaternion or Vector3
    6.      Debug.Log(anim.time);
    7. }
    8.  
    If we consider that my animation is about 0.8s when I look at the debug information the anim.time is always < 0.8s by at least 0.1s. So when the animation starts, it starts at 0, then increase over time from 0 to 0.1, 0.2, etc. up to 0.74 for example but never to 0.8s. In the next round, sometimes the end value is 0.78, then 0.791 or 0.787, etc.

    Is there a reason why it never reaches the full length of the animation?

    The problem I have is that my transition between my two animations [walk / turn] and [Idle] have a really tiny glitch (popping).

    I used Crossfade, but it doesn't seem the fix the issue. I also don't execute it in update or fixed update (it was causing more issue in these methods). On PC the glitch is not so important, but on Ipad it is really more visible.

    Thanks for helping.