Game dev
Saved & recent

Finite state machine

Also called: FSM, state machine

Related terms: state, transition, behavior tree, animation state machine

A set of named states and rules for moving between them. A simple enemy can be in patrol, chase or attack. Exactly one state is active in a basic FSM; transitions happen when their conditions are met.

Each state can have entry, update and exit behavior. FSMs also suit doors, menus and character abilities. As transitions multiply, hierarchical states or a behavior tree can make the logic easier to manage.

Further reading
Robert Nystrom: State, Game Programming Patterns
closed opening open closing open request open limit timeout closed switch obstruction
Opening owns the door behavior in this frame. Reaching the open limit hands control to the open state. An obstruction while closing can send it back to opening.

View in the full Game dev collection