Enemy AI
How enemies decide
How an enemy picks what to do next, tick after tick: its states, its priorities and the rules that settle a choice.
- Sheet
- 12 of 18
- Latest release
- v0.42
- As of
- 2026-10-22
Sixty times a second, every enemy asks the same questions in the same order: am I able to act, has the level told me to do something, am I in danger, who am I fighting, and what does my current state ask of me? The answers come from a small set of states, a fixed order of priorities and a few plain rules, so a creature behaves the same way every time it meets the same situation.
An enemy's states
The states
An enemy is always in exactly one state, and the state says what it is doing: resting, chasing, attacking, searching or fleeing, plus the two interruptions every body can suffer, a stagger and death. Every way of waking it (a wound, a noise, a call, a sighting; see What enemies can do) goes through the same door into the fight, and there is one door out of it. Whatever the fight left behind is cleared on the way out, so a creature that gives up is calm again.
Fight or flight is re-decided every tick, never fixed once. A creature runs when it is a coward by nature, when it is badly hurt, or when it has no usable weapon left. Once it has healed a little past the line, it turns and fights again; the small margin stops it flickering between the two.
One tick, and who wins it
The simulation moves the whole world in ticks, and an enemy's turn inside a tick always runs in the same order: it decides before it moves, and turns to face where it is going only after it has moved.
- Can I act?Dead or paused bodies stop here
- ClocksTimers, wounds and the stagger run down
- WeaponsReload, cool down, raise a better gun
- DecideLevel orders, air, then the state's behaviour
- MoveWalk, climb, swim, fly or hop
- React and faceDodge, then turn to look
- 60
- ticks a second: every enemy decides sixty times a second
- 11
- fixed priorities settle who controls a tick
- 4
- rungs on every settings ladder
As of 2026-10-22.
Several things can want an enemy's legs at once: a level's script, a drowning reflex, a grenade at its feet, the fight itself. A fixed list of priorities settles it: the first one that claims the tick wins, and everything below it waits. Nothing is weighed or scored, which is why behaviour stays easy to predict, and why a game can add a behaviour of its own without rewriting the engine's.
| Rank | What claims the tick | Why it outranks what follows |
|---|---|---|
| 1 | Dead, or out of play | Nothing else exists |
| 2 | Its part of the level is paused | An absent body does nothing |
| 3 | Staggered | The interruption is the loss of the turn |
| 4 | The level's orders | A level's script outranks the creature's own wishes |
| 5 | Seeking air | Drowning beats every goal, even a half-finished attack |
| 6 | Self-preservation | A step into a deadly liquid or off a ledge is refused, whatever wanted it |
| 7 | Fleeing | Re-decided every tick from health, arms and nature |
| 8 | A game's own errand | A behaviour a game adds can claim the legs for a moment |
| 9 | Dodging | A reflex borrows the legs for a few ticks, then hands them back |
| 10 | Positioning in the fight | Closing in, holding range, surrounding, hiding |
| 11 | The state's own behaviour | Resting, searching, travelling |
Who to attack
Each tick an enemy settles its target with one short list, checked top to bottom. The first line that gives an answer wins; there is no scoring and no dice.
- Whoever hurt me, whatever side they are on, as long as I can still see and reach them. This is what makes infighting work.
- The nearest hostile player I can see, so a pack does not lose interest in the person playing because a rat wandered closer.
- The nearest other hostile I can see.
- Nobody in sight: the player I was already chasing, or the nearest one I know about. This is a name to keep looking for, not a licence to walk through walls at them.
When a target dies, the next one it has noticed takes over. Sides and grudges are on Statuses, factions and pickups.
Losing you, and giving up
An enemy keeps two places apart, so it can act on a hunch without cheating. The last place it actually saw you can only be set by its eyes, and that is where it keeps firing. Where it thinks you might be comes from a noise, a wound or an ally's report; it walks and searches there, but does not waste shots on it.
When it loses sight of you, a short memory keeps it heading for where you really went. Then it works through its search stages, which a game can reorder, repeat or leave out for a creature that should never search. A search ends on clocks, never on a whim: when the time runs out, or the stages do, it stands down and goes back to resting. A creature that can see you but cannot reach you gives up the same way.
One ladder for every setting
Almost every number an enemy uses, from how long it searches to how far it keeps away, is answered by a short ladder, from the most specific rung to the most general. The first rung that states a value wins.
A game can swap in its own behaviour for any state, or even give a creature a whole brain of its own, but the body, the clocks and the doors into and out of a fight stay the engine's. How a game supplies its numbers is on Tuning and content plug-ins.
Crowds: predictable and affordable
Patterns instead of dice. Much of what looks random in a crowd, such as how a route bends or which hiding place is checked first, is a fixed variation worked out from each creature's identity. Where real chance is wanted, it comes from the world's own dice, which roll the same way on a replay. Either way the same situation plays out the same way every time; Simulation and replay explains why that matters.
Groups share one plan. When a group surrounds you, one coordinator for the whole world hands out the positions, rather than each creature planning on its own. If a member gets cut off, the group drops the tactic and each member fights on its own.
Many enemies at once. To keep big crowds cheap, a game can let calm creatures far from every player think only every few ticks, while their bodies still move every tick. Any creature in a fight or near a player always thinks every tick.
Read on:
- What enemies can doThe full repertoire these decisions choose from.
- NavigationHow a decision to go somewhere becomes a route.
- Weapons and projectilesThe weapon rung of the ladder, and what fires.
- DamageThe hit that wakes, staggers or kills.