Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Animator - Set the DefaultState 'Motion' field based on the current combat position state

Discussion in 'Animation' started by maris-otter, Jan 23, 2021.

  1. maris-otter

    maris-otter

    Joined:
    Jun 10, 2020
    Posts:
    11
    Hello,

    Just getting into using the animator for a turn based fighting game. Here's some info about my setup

    I have one animator that changes animation states based on triggers i send via code 'AttackMove' for attacks, and 'DefendMove' for the animated reactions to the attacks (triggered by a different gameobject - the opponent). To allow for different abilities having different animations, I use an Animation Override Controller to temporarily change the animation controller for the ability. This all works well. I've attached a picture of my animator setup


    What I am having trouble trying to figure out how to do is change the defaultstate motion value after a fighter uses there abilities, IF the combat Position State has changed. For example, a fighter could use a takedown ability and if successful, fighters would be positioned on the ground, not standing up. Without some sort of change to the animation controller, the fighters would animate the takedown, but then immediately appear standing back up as Motion field is set to the default standing state - 'Player Stance Idle 256'

    Does anyone know how to have the DefaultState change based on a condition I provide via code? Or is there another easier way?

    Thanks!
     

    Attached Files:

  2. maris-otter

    maris-otter

    Joined:
    Jun 10, 2020
    Posts:
    11
    My question might be too specific, does anyone have any tips or useful tutorials to check out for using the Animator alongside a combat state machine?

    Thanks
     
  3. Inxentas

    Inxentas

    Joined:
    Jan 15, 2020
    Posts:
    277
    If you are 100% sure your animations can't be interrupted, why not look into Animation Events? I am in a hurry so I can't type a full tutorial, but you can add events to a timeline (in the grey bar above the dope sheet) that can fire a bit of code.

    You could also make it so there's a "prone" state (I don't see this state in your PNG yet) rigged in such a way it will move through a "standing up" state before running the new attack animation. So when it's in the "prone" state, changing some Animator parameter would have the standup animation play first, which could lead into the actual "punch" animation smoothly by adding some Exit Time to the "standup" animation.

    It depends a bit on the particularities of your game which method would be best. I'd use the first method if I'd need to actually update positions. I'd use the second if it was grid based and there's no gameplay penalty for standing up from a prone position.
     
    maris-otter likes this.