Search Unity

Not getting the fast, short, successive animation chains I want

Discussion in 'Animation' started by brimby, Jul 28, 2014.

  1. brimby

    brimby

    Joined:
    Jul 28, 2014
    Posts:
    4
    I've created a quick "jab" animation for my character with the intention of the player being able to press the punch button basically as fast as he wants and having the animation cut off the old one and restart anew over and over. So far it is not working at all.

    I placed the "jab" animation in the animator twice, with a transition between the two copies that is the same in both directions: if the appropriate attack trigger is set by way of GetButtonDown it runs the animation. Both also have transitions leading back to the "standing" animation if the exit time is reached. I thought this would allow the animation to start itself over back and forth. Apparently not.

    Other behavior I'm seeing that I don't understand:

    1. When any of my animations run, the blue bar that shows its progress in the animator runs to the end at seemingly the right time, but then the bar starts over and runs about halfway through again, even though the animation already ended. I do not have loop time enabled.

    2. If I create an animation that is exceedingly fast, it plays differently in the animation preview than at runtime. For instance if I make my jab too fast, rather than the hand reaching all the way up to shoulder level before returning back to the hip like it does in the preview, instead it only makes a small attempt to reach out before coming back in.​

    I'm sure my issue is fundamental as I'm still getting the hang of things. But if you can get me on track to having fast repeatable animations, I'd be grateful.
     
  2. TMPxyz

    TMPxyz

    Joined:
    Jul 20, 2012
    Posts:
    766
    Animator.Play
    void Play(string stateName, int layer = -1, float normalizedTime = float.NegativeInfinity);
    void Play(int stateNameHash, int layer = -1, float normalizedTime = float.NegativeInfinity);

    You could call Animator.Play() whenever you press punch key, set 'normalizedTime' to 0.0 to start from beginning.
     
    vctr_ro likes this.
  3. Bezzy

    Bezzy

    Joined:
    Apr 1, 2009
    Posts:
    75
    Click on the transition(s) to the jab. In the inspector you should reduce the crossfade to nothing in order to have an instant/blendless transition.

    The reason you've got extra looping is again, down to the transition start/end. If you set the end of a transition to occur outside the "previous preview" animation, it will need *something* to cross fade *from*, so it will just loop the preceding anim. So, keep your transition start/end inside the body of the previous anim so that it doesn't have to create a loop for its source.

    (I think, anyway)
     
  4. brimby

    brimby

    Joined:
    Jul 28, 2014
    Posts:
    4
    Thanks guys. I tried Bezzy's procedure first and it worked. I'll keep TMPxyz's ideas in mind if I need to do anything programmatically.