Search Unity

Transitioning from one anim to another based on which frame the anim is in

Discussion in 'Animation' started by jasonargoargo, Sep 11, 2019.

  1. jasonargoargo

    jasonargoargo

    Joined:
    Aug 10, 2019
    Posts:
    3
    Using 2018.4

    I am using 2D sprites in a 3D environment (with Blend Trees to imply three dimenionality upon camera rotation), and my Animator for the player gameObject needs to be able to switch between several different animation clips based on which frame the clip is at.

    For instance, I have an idle anim wherein the player gameObject shifts her weight from one foot to the other. I also have two "transition" anims, one for each foot. And I also have a walk anim. So if the gameObject is, say, between frames 0-20, then needs to transition to the "leftFoot" transition anim before then transitioning into the walk anim. Similarly, if the idle anim is between frames 21-40, the gameObject needs to transition to "rightFoot" transition anim followed by the walk anim.

    Does this make sense?

    I think I'm on the right track by looking up Unity scripting documentation about the Animation and AnimationClip methods, but I'm not sure which functions are helpful in this case. And are certain Animator parameters better to use over others (bools, triggers)? Any help would be appreciated.
     
  2. coslor

    coslor

    Joined:
    Jun 19, 2017
    Posts:
    3
    I'm afraid I can't help with the API, but there's always a simpler alternative: break your idle anim into sections, like "idle_left" for frames 0-20, and "idle_right" for frames 21-40. Then, your state transitions would look like:
    • idle_left -> leftFoot->walk
    • idle_right->rightFoot->walk
    Just a thought.
     
  3. jasonargoargo

    jasonargoargo

    Joined:
    Aug 10, 2019
    Posts:
    3
    That's brilliant. I can just have several of my anims already split up, looping only once before transitioning to the other (back and forth) and, when the gameObject is moved, it'll already know to transition to the appropriate transition anim before going to walk anim. Similarly, I'll split up my 12-frame walk anim into two parts (left leg forward and right leg forward, 6 frames each) and have it connect back to leftFoot and rightFoot except have the anims play backwards before going into idle.

    Thanks!