Stage 2 · Lesson 6 of 7
State machines
A treats an object as being in exactly one state at a time, such as idle, running, jumping, attacking or hurt. It also sets clear rules for moving from one state to another. This replaces a tangle of (true or false flags) like isJumping and isAttacking, which allow impossible combinations.
Start with an (a fixed list of named options) and a switch or match statement. Once the states grow, move to one class or node per state. Player controllers, enemy AI, menus and match flow all use state machines. Your engine's animation system is one too.
Common trapadding a new boolean for each new behaviour until the player can attack while dead or jump while in a menu.
A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- CourseFreeLearn GDScript From Zero
GDQuest · Beginner
A free browser app that teaches GDScript from zero with checked exercises
- CourseFreeGodot Docs: Your First 2D Game
Godot Engine · Beginner
The official complete first game: scenes, signals, input, spawning and a HUD
Practise
Keep handy
Also worth your time
The official guide to connecting, declaring and emitting signals
- Game Programming PatternsGo deeper
Free book on the state, observer, component and other patterns games rely on