Search Unity

Animation.Stop() freezing character instead of rewinding animation

Discussion in 'Scripting' started by Zethariel1, May 30, 2012.

  1. Zethariel1

    Zethariel1

    Joined:
    Mar 21, 2012
    Posts:
    439
    Hi everyone!

    I have encountered a most pecular bug -- and since my knowledge in animation isn't perfect, I belive it is something I'm not seeing...

    I have a script that is fired on the player when he gets hit -- it stops all other coroutines and animations and makes the player be knocked back. The StopAllCoroutines() works great, but animation.Stop() isn't working as I would expect it to -- if there was an animation in progress, it simply freezes it and the player is locked in a bizzare pose until a new animation is played. From the reference I understood that animation.Stop() stops all animations, which is what I wanted -- and some of the animations were run from coroutines (which shouldn't matter, they could be launched from anywhere I believe.) The script responsible for stopping the animation is simple:
    Code (csharp):
    1.  
    2. public virtual void IsHit()
    3.     {
    4.         if (isHit)
    5.             return;
    6.         else
    7.             isHit = true;
    8.         canMove = false;
    9.         enemyModel.animation.Stop();
    10.         StopAllCoroutines();
    11. // ............ unimportant stuff later
    12.  
    Here is a screenshot of what happens:


    As you can see, the red pony is locked in an awkward position. Anyone has any clue what could be wrong?
     
  2. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    erm, You are stopping all animations but not starting any. It leaves it in the last pose because you are not specifying any animation to start.

    Consider simply crossfading a new animation onto your model, instead of stopping everything.

    Note: you can stop certain animations if you have layered animations.

    animation.Stop("Aim");

    This would stop a certain animation and cross fade it back to underlying animations.
     
  3. Zethariel1

    Zethariel1

    Joined:
    Mar 21, 2012
    Posts:
    439
    Ah, I knew it would be something that simple >.< Lemme try it.

    EDIT: No dice. I added an Idle anmation, that was simply no rotation/movement (added flat curves to make sure of that) and then added the line enemyModel.animation.Play("Idle"). The character was still locked in the awkward upward-facing-dog position.

    EDIT2: Okay, that was me being retarded again. I changed the animation some more, and now it works like a charm. Thanks for your time!
     
    Last edited: May 30, 2012