Posted April 09, 2020 by sevencrane
#tech discussion
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.
First question: why on earth would you do this, why not script it? Why combine the animator and the AI states?
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.
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.
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 :~)