HomeAI & Machine LearningFinite-State Machines: How Games Simulate an Opponent's Decisions

🤖 Finite-State Machines: Enemy AI

An interactive 3D enemy AI agent visibly cycling through patrol, chase, attack and search states as a finite-state machine, with adjustable detection radius and state-transition rules.

AI & Machine Learning3DAdvanced60 FPS
finite-state-machine-enemy-ai-game-simulation-lab ↗ Open standalone

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.

⚙ Under the hood

An interactive 3D enemy AI agent visibly cycling through patrol, chase, attack and search states as a finite-state machine, with adjustable detection radius and state-transition rules.

artificial intelligencefinite state machinegame aiagent simulationstate transitionsmachine learningThree.js

3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)