Animator State Machine AI


I'm polishing the Richter boss fight in the Night Market. I've achieved a decent AI by combining her animator state machine with her AI logic, augmented with external param-settings sensors and state machine behaviours. No external Unity assets required, and everything is modular.

Why

First question: why on earth would you do this, why not script it? Why combine the animator and the AI states?

  1. The AI is gonna be a finite state machine one way or another, we're not making neural nets here
  2. AI behavior decisions largely depend on which animation state it's in
  3. Visually editing the AI state machine is faster, easier to read, and easier to maintain than scripting a state machine
  4. I can make another boss fight with the resources here without writing a single line of C#

How

Here's how I implemented it, in 5 steps.


Step 1: Prototype the state machine on paper with the fight in mind. I want this enemy to be punish-based, so they're going to remain ~3 tiles away from the player if they can. If the player enters their zone, they'll either dodge or throw out a quick counter. If the player is still near them after a spacing modification, they'll throw out a larger, more mobile attack. 

In the end-lag after an attack they'll be staggerable, so if the player can close the distance with a dash they'll be able to get a good combo off.


richter state machine
red arrows are randomly chosen transitions

richter sub-state machine

the "maintain spacing" sub-state machine

Step 2: Without making any of the actual animations, create the state machine in Unity. 



Step 3: Hook up sensors that will set the parameters you need. The implementation of said sensors is left as an exercise for the reader.


this is the second iteration of the boss, we don't talk about the first

Step 4: Add state machine  behaviours to track simple things like movement and player orientation. Not shown, but I also have a "random transition in state" that will, you guessed it, instantly choose a random next state to play from a given list.


Step 5: Animate. I set fine-grained properties like staggerable frames during animations, instead of at the state level via state machine behaviours.


Step 6: Playtest and keep iterating :~)

Get Vapor Trails

Download NowName your own price

Comments

Log in with itch.io to leave a comment.

(+1)

dude just played the demo this game looks and feels so good. i hope this becomes big game soon

thanks! I'll be pushing an update in a week, you should check it out.

(2 edits) (+1)

Also if you're able to release this game on steam you should.

 I think this game is gonna be a big hit one day! So keep up the good work and never give up! Because people like me are looking up to you!!!

Your words fill me with determination. Thank you.

(+1)

i like how you're developing this game!

(+1)

pretty cool!