Why a state machine
Most enemies and many players boil down to a handful of states: standing, walking, chasing, attacking, getting hurt and dying. Written as a pile of if statements, that logic gets tangled fast and a new behavior breaks two old ones. A state machine keeps each state on its own card with clear arrows out of it, so you can see at a glance why an enemy suddenly stops chasing or never attacks.
States, arrows and conditions
Click a state to edit it on the left. Give it a name, an optional animation that plays when it starts, and notes for what happens on enter, every frame and on exit. Each arrow out of a state has a condition such as player_distance < 120, hp <= 0, state_time > 2 or hit and hp > 0, and a priority. When several arrows are true at once the highest priority wins. Conditions understand and, or, not, the usual comparisons, math and abs, min and max.
Transitions under From any state are checked first in every state, which is the clean way to send an enemy to Dead or Hurt no matter what it was doing. They never fire into the state the machine is already in.
Test it live
The simulator under the board runs the machine ten times a second. Drag the sliders to move the player closer, lower the health or flip a switch, and press a signal button to fire a one-shot event like a hit. The current state lights up on the board and every change is written to the log with the condition that caused it. The checker lists states that can never be reached, states with no way out, conditions that do not parse and names that are not defined.
Export to your engine
| Format | What you get |
|---|---|
| Godot 4 | One GDScript file: an enum of states, your variables as @export fields, a state_changed signal, trigger("hit") for signals, enter, update and exit sections with your notes, and optional AnimationPlayer playback. |
| Unity | A C# MonoBehaviour with the same structure: public fields for the inspector, a StateChanged event, Trigger("hit") and Animator playback. |
| JSON | The whole graph, to drive your own runtime or keep in version control. |
| Diagram | A PNG of the board and a Mermaid state diagram for your design docs. |
The generated code runs as it is. Fill in the enter and update sections with movement and attacks, set the variables from your game each frame, and the transitions take care of themselves.
Your work stays yours
Everything runs in your browser and is saved in it. Editing, testing and saving a project file are free. Code export is part of GameShipKit Pro.