Search Unity

Question Prevent Takehit animation connected from Any State interrupt an Rolling animation.

Discussion in 'Animation' started by hvtanh07, Apr 16, 2022.

  1. hvtanh07

    hvtanh07

    Joined:
    Nov 14, 2020
    Posts:
    8
    I have Any State connected to Take hit animation, however, when playing Roll animation I don't want rolling animation to be interrupted, but every time player take hit, the rolling will stop immediately and play Take hit animation. Is there any way to make an exception for some animation not to be interrupted by animation connected from Any State? Screenshot 2022-04-16 131107.png
     
  2. Flylake

    Flylake

    Joined:
    Feb 26, 2014
    Posts:
    12
    As the name implies, the "Any" state functions as essentially any state in your animation tree

    The only way to prevent an unwanted transition is to add conditions to the transition itself like you would any other.

    Add a new boolean value under Parameters, call it "Rolling" or something along those lines.

    Click the transition arrow between "Any State" and "Take Hit" and add the condition "Rolling Fase".

    Then get settled in because now you have to manage setting and unsetting that boolean flag from a script.


    An alternative is to not have the transition from Any State => Take Hit at all, and instead from your script (whichever manages the character) to call the animation directly through the Animator

    ex.
    Animator myAnimator <== This would have to be a variable on the script itself, and assigned through the inspector
    If(TookHit)
    {
    myAnimator.Play("Base Layer.Take Hit", 0);
    }