Search Unity

Mecanim and Animation Events

Discussion in 'Animation' started by Nanako, Mar 15, 2015.

  1. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    okay, here's the situation.

    My character can attack, by swinging his weapon. And once he starts an attack, i set the animator bool isAttacking to true. Thusly preventing the attack from being interrupted

    Near the end of the attack animation, is an animation event. It calls a function which sets isAttacking to false, allowing farthere attacks to be done. I deliberately have this NEAR the end, not AT the end. so that there's a short period of relaxing back to normal stance where the animation is technically still playing, but as far as i'm concerned the attacking part of it is "done" and i want to allow more attacks to happen.

    Now the problem is, if i spam click the attack button, it breaks. If i attack again during that winding-down period, isAttacking is set to true, but the attack animation is already playing, already past the ending point, and it does not restart. This causes me to get locked in a situation where i'm no longer attacking, but isAttacking is still set true and i can't start a new swing.

    What i would like to happen is, if isAttacking is set to false, the attack animation starts anew, whether or not it's currently finished. How might i accomplish that?

    picture:
     
  2. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    One thing you could do is a transition from Swing to Swing, a transition to self that would allow to you to chain your attack animation without a transition back to default state.
     
  3. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    thank you, i asked this on unity answers too, and someone told me about Triggers.

    using one of those, i was able to set a transition from AnyState to swing, when the trigger was set, and then just set it whenever i attack. That worked nicely.