Ai
-
Finite State Machines
A* tells your guard how to reach the player. It doesn’t tell the guard whether to bother. An entity that only knows how to move isn’t thinking — it’s executing. A Finite State Machine is the decision layer: a formal description of what an entity is doing right now, what it might do instead, and exactly what must be true for it to switch.
Every guard in every stealth game runs on something like this. So does every enemy AI in a platformer, every shop NPC that goes idle when you walk away, every boss that enters its second phase at half health. FSMs are ubiquitous in games because they map directly to how designers describe behaviour: if the player is near, chase; if the player escapes, give up and return home.
-
Behaviour Trees
A Finite State Machine with four states is manageable. One with ten states, where any state might transition to any other, is a maintenance problem. Behaviour Trees solve this by replacing the transition table with a tree of composable nodes — small, reusable pieces that combine into arbitrarily complex behaviour without the O(n²) transition explosion.
A Behaviour Tree is evaluated top-down every frame. Each node returns one of three values:
SUCCESS,FAILURE, orRUNNING. Parent nodes use these return values to decide which child to run next. The result is that you describe AI behaviour as a hierarchy of priorities rather than a flat list of states. -
Influence Maps
Pathfinding tells an entity how to reach a destination. It doesn’t tell the entity which destination is worth reaching. An influence map fills that gap: a second grid, the same dimensions as your tile map, where each cell holds a numeric value representing some property of that location — how dangerous it is, how much of the area a faction controls, how recently the player passed through.
The guard doesn’t need to pathfind to every tile to know that standing in the open near the player is a bad idea. It reads the influence map, finds the cell with the highest “danger” value, and moves away from it. Spatial reasoning without exhaustive search.
-
Steering Behaviours
Grid movement is discrete: an entity occupies a tile, moves to an adjacent tile. That works for turn-based games and many real-time ones. But the moment you want an enemy that smoothly curves toward a target, a projectile that arcs, or a group of guards that spread out without running into each other, you need movement that operates in continuous space.
Steering behaviours — introduced by Craig Reynolds in 1999 — describe motion as the difference between where an entity is heading and where it wants to head. That difference, the steering force, is applied to the entity’s velocity each frame. The result is motion that looks purposeful and organic rather than grid-snapped.