What it does
A guard has a position, a facing, a view range and angle, a hearing range, a suspicion level, a mode and a memory. While it can see the target, inside its cone and with no wall in the way, its suspicion rises; when suspicion reaches 1 it raises the alarm. Out of sight it remembers the last-known position for a while, searching there and calming slowly, then forgets and calms quickly back to patrol. The target's visibility shrinks or extends the distance at which it can be seen, and zero makes it invisible, so shadows, sneaking and lamps all come down to one number.
Noises are positional: a running footstep or a thrown decoy reaches every guard within the smaller of its hearing and the noise's radius, cut down when a wall is between them. A noise raises suspicion and sends the guard to investigate, but by default it can never raise the alarm on its own. When a guard does raise the alarm, it radios the others within reach, who search the reported position with raised suspicion; they do not see the target themselves. Every change is explained in the drained events, with a reason and a position, which is what a HUD or a debug view needs.
How fast sight fills suspicion is one gain function of the guard, the target and the distance. The stock sightGain
can fall off with distance and scale with the target's visibility, and your own function can do anything else, such
as a captain who notices twice as fast or guards who sharpen once the gem is taken. A game that moves its own guards
(with patrol routes, a state machine, sprites) hands their poses over each step and reads their beliefs back.
Features
- Sight cones — range, angle and wall occlusion through
visibility-2d, or your own line-of-sight test. - Suspicion by degrees — a tunable gain per guard, target and distance, from instant spotting to slow, distant doubt.
- Target visibility — one number for shadow, sneaking or a lamp, scaling how far and how fast a target is seen.
- Hearing — positional noises muffled by walls, raising suspicion without raising the alarm alone.
- Memory and search — last-known positions, a memory time, and separate cooling while remembering and after forgetting.
- Four modes — patrol, investigate, search and alert, with events explaining every change.
- Radio — the alarm reaches allies within a set reach, who search without seeing.
- Guards you move — update poses, add reinforcements and remove guards mid-game.
- A seeded infiltration level — rooms, a key, an exit, patrolling guards, decoys and a certified winning route, with an option to build it in a worker.
- A bot —
infiltrationBotplays with ordinary sneak input along cover-aware paths, and can lose.
Good for
- Top-down stealth games with patrolling guards, cones of vision, noise and alarms.
- Heist and infiltration levels where the player takes a key or a prize and gets out unseen.
- Light-and-shadow stealth, where the target's visibility changes with lamps, shadows and sneaking.
- Stealth sections in other genres, such as guards in an RPG town or an action game's quiet level.
- Detection meters and AI decisions, reading the current rate of suspicion for a HUD or an enemy's choices.
Make it yours
The installer has no options; you pass guards, walls and settings to createStealth. The settings are the gain
function, the memory time (default 4 seconds), cooling while remembering and after forgetting, how walls, scale and a
cap shape hearing, the radio's reach, the suspicion it gives and how long it is remembered, and an optional
line-of-sight test of your own. sightGain takes a rate, a distance falloff and a visibility weight. The infiltration
level takes every number it plays by: the room, the number of guards, their range, field of view, speeds and
patrols, the player's speeds and size, footstep noise, decoys, what gets you caught and the reach of the key and the
exit.
Two very different sets of guards from the same code: a sleepy keep, with a two-second memory, fast forgetting, hearing that walls block completely and no radio; and a garrison on alert, with a ten-second memory, no calming while remembering, sharp hearing through walls and a radio that reaches three times the larger hearing range and sends allies in at high suspicion.
A quick look
A guard, a wall, a noise and a step, with the events drained:
import { createStealth, guard } from '@phaser-ae/stealth';
const stealth = createStealth([guard('watch', 100, 100)], [{ x: 160, y: 60, w: 40, h: 120 }]);
stealth.noise({ x: 90, y: 140, radius: 100, strength: .5 });
stealth.tick(1 / 60, { x: 200, y: 100, visibility: 1 });
const feedback = stealth.drain();
Works with
visibility-2d— required: the line-of-sight queries behind every sight check.arena-layoutandnav— the rooms and flow grids the infiltration level's guards walk.fsm— for patrol routes and behaviour of your own, handing poses back to the guards.
Good to know
- It is 2D only.
- With the general API your game moves the guards; only the infiltration level moves its own on patrol and search.
- Radio is range-based and needs no line of sight, and hearing is a distance test cut by walls, not sound travelling round corners.
- The generated level proves at least one timed escape; it does not promise that every configuration you build has a winning route.






