Finite State Machines are a great tool for simplifying a system where an Entity has many states it can be in with different conditions that determine what state to transition to. This works well for representing a Player in a platformer, because the state machine can keep track of what state the Player is in based off of user input. This state machine would largely be based around animation states (running, jumping, attacking, etc...)
However, although this makes sense for handling Entity states and keeping track of animations, what about AI states? FSMs also provide a great framework for handling how enemies behave when interacting with the Player. My question is, what is the relationship between this FSM and the FSM that handles general entity states?
For example, in general, an enemy can be running, attacking, idling, jumping, falling, crouching, etc... In terms of AI, the enemy could be following, attacking, running away, patrolling, etc... As you can see, these states are mostly different with some overlap. I want to know how to handle these two different FSMs in code.
Questions:
- Should I keep these FSMs separate and update the states separately or should I somehow combine them into one FSM?
- If I keep the FSMs separate, how can I can I handle interdependence (behavior in the AI might change if suddenly the Enemy walked off a cliff and is now falling)?