← /browse

Making Games / 3 min /

How does a game enemy decide what to do? State machines for beginners

Ever wondered how a game guard knows when to chase you? Most enemies run on a state machine: they are always in exactly one state, like patrol, chase or attack, and a few simple rules decide when to switch.

Drag the player around the demo, change the chase and give-up distances, and see why two different distances stop the guard from flickering. Then sketch your own enemy with three states.

Diagram of three circles labelled Patrol, Chase and Attack joined by arrows, beside the article title

More in Making Games

all Making Games →