← 🤖 Algorithms & AI

🤖 Enemy AI FSM

PATROL
CHASE
SEARCH
ATTACK
State: PATROL
Time in state: 0.0s
Distance to target:
Transitions: 0
FPS:
Drag — rotate · Scroll — zoom · Click ground — move target (manual mode)

🤖 Finite-State Machines: Enemy AI

A robot guard patrols a fixed loop and switches between patrol, chase, attack and search states purely by re-checking simple distance rules against a moving target — the same logic pattern that drives enemy behaviour in countless games.

🔬 What It Demonstrates

Every frame the guard is in exactly one named state; transitions fire only when a hard condition (distance to target vs. detection radius or attack range, or a search timer) is crossed — no hidden memory, no learning, just rules.

🎮 How to Use

Adjust detection radius, attack range, guard speed and search patience, then watch the state diagram and the guard's eye colour update live. Turn off autopilot to click the ground and drive the target yourself.

💡 Did You Know?

FSMs are deliberately simple by design — that predictability is what let designers hand-tune Pac-Man's ghosts in 1980 and still lets modern stealth games telegraph "the guard heard something" today.