I’m trying to figure out the correct way to set up the animation states for this. Right now I have each one as a sub-state with four animations inside. The attacking animations have an exit time (i.e. should be uninterruptable), and the idle/walking ones don’t.
What I want is to be able to use the following triggers:
idle, walk, attack, faceUp, faceDown, faceLeft, faceRight
And basically any of those animations should be able to transition into any other animation given the right triggers. My first attempt at doing this was using the “Any State” within each sub-state as the origin, but I find that if I do this then the attacking animations get interrupted, i.e. Any State takes precedence over the exit time. I feel like I’m doing it wrong and should be making better use of the entrance/exit states somehow, but it’s not quite working how I expect. Anybody have any pointers about the best setup?
Also, related question: any way to change the default transition settings to “Has Exit Time = false” and “Transition Duration: 0”? Really tired of doing that manually
I’m in a similar situation. What I did, was like you, have 4 substates, one for each direction. Then, I had a “direction” value, with five possible values, one for each direction, and one for idle.
Then my transitions are:
AnyState → Walking, for each of the directions, when the direction value = that direction.
Walking → Idle, in the same direction, when direction = 0 (idle value).
Idle → Attacking, when trigger attack is true
Attacking → Idle, when attack animation is complete
In my case you can’t move and attack. I prevent the attack animation interruption by changing direction in that I ignore change direction commands in the code, until the attack is complete.
Would love to hear if others have more efficient ideas. I still have to do everything x4 when I add a new state…
At the top level the transitions are simple: Idle transitions to Walking if walking = true and attacking = false. Likewise Walking transitions back to Idle if walking = false and attacking = false. Repeat for the other top level state combinations, no need to worry about facing at this level since it doesn’t affect which top level state is chosen.
Then within a sub-state you only have to deal with entry and exit. Within Walking, Enter transitions to Walk Up if facingUp = true. Walk Up transitions to Exit if walking = false OR facingUp = false OR attacking = true. Rinse and repeat. This way even if I’m walking up and then I start walking right, the animator will simply exit and re-enter the Walking state and re-evaluate then what my facing is.