Feature Library

Agent senses, cover and squads

0.73 GPU · 0.60 CPU ms
A still of the Agent senses, cover and squads demo
Still
The live demo starts when it’s in view.Tap the ground: the lead calls the squad there · drag to orbit

Agents that see, hear and hide as a group.

What it costs a frame

0.73 ms
0.60 ms
GPU
0.73 ms
CPU, median
0.60 ms
CPU, 95th pct
0.84 ms
Draw calls
99
Weight
Moderate

Measured 13 November 2026 on RTX 4060 Laptop, 13th Gen Intel(R) Core(TM) i9-13900H, Chrome 157, 1920×1080 at 1×. 600 frames × 3 rounds, median kept (rounds ranged GPU 0.47–0.73, CPU 0.60–0.81 ms). What ran: Measured as it runs by itself: eight agents hiding from the sweeping light on its moving mast, two lookouts taking turns, call-outs and regroups as they happen; sight cones (34 rays each against 30 solids at 30 Hz), cover spots, call rings and a 1024² spot-light shadow on. Phones: tiers are being measured next.

On every machine it was measured on
MachineGPU msCPU msCPU p95
RTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900Hreference · measuring tool0.730.600.84
apple · Apple A19 Proin a browser tab · 16 November 20263.980.743.74
Intel Arc 140V (Xe2-LPG) · Intel Core Ultra 7 258Vin a browser tab · 15 November 20262.491.492.25

Bars against one 16.7 ms frame. A browser-tab run is timed in a visible tab without the tool’s scripted input, so read it as close, not exact.

What it needs

Renders with
WebGPU or WebGLWebGPU where there is one, WebGL2 where there is not.
Your browser
Runs hereNo WebGPU needed
Depends on
three.js 0.187.0No other packages

What it’s for

  1. Sentries and watchers that see and hear in a stealth game
  2. A group of agents that hide from a light, a camera or a patrol
  3. NPCs that take cover behind walls and crates without hand-placed cover nodes
  4. Turn-taking so only a few agents act at once (look out, go first, speak)
  5. Wildlife that hears footsteps and flees together
  6. Crowd or evacuation simulations where people call to each other and regroup
  7. Minimap sight cones that respect walls

Pitfalls, in brief

  1. A cover spot hides only from the side it faces: protects(spot, threat) must be well above 0 (scoreCover wants 0.45), and the spot still needs a line check from the threat’s eye to a body tucked behind it.
  2. Give the threat’s y as the height it sees from (a lamp’s head, a sentry’s eyes) and test the watched body’s chest, not its feet: feet are behind every kerb.
  3. The cover field caches per collider set by identity: pass a new colliders object when walls move or break, or it keeps the old spots.
  4. Cover searches are rationed (searchesPerStep, shared by every body): a squad of twelve finds its spots over a few steps, not in one.
  5. A mind never searches itself: it sets wants, and only the director hands it a spot.
6 more in brief
  1. band defaults to the source’s fighting distances (a quarter to seven tenths of the body’s range).
  2. A call’s front travels at speed: a listener is told when it passes, not when it is called.
  3. A relay is a new call with relayOf set to the first one: nobody hears the same news twice, so relays spread outward without echoing back.
  4. Hush and turns pull against each other: a hushed lookout keeps its turn but does not peek, and loses the turn after 1.4 s out of touch.
  5. sightFan is level at the eye: a viewer behind a wall taller than its eyes sees nothing past it, and over a lower one sees everything.
  6. Facings are atan2(dx, dz) (0 along +z), as three.js yaw is.
11 pitfalls in full, the hook-up guide, the module source and its tests come with the part.

Where it comes from

From HaTac. Fully custom code.

Chris Wellons, “lowbias32” integer hash (hash-prospector): The finalising constants of sweepPhase’s hash (public domain).

Hart, Nilsson and Raphael, A* search (1968): The walk grid’s search. The algorithm, not code.

Slab test for a ray against a box (Kay and Kajiya, 1986): segmentHit clips the line against each box’s three slabs. The method, not code.

aiagentsnpcperceptionsight coneline of sighthearingcovercover pointssquadgroup behaviourturn takingstealthsearchlightcall-outsregrouppathfindingwalk gridstate machinethree.jsno dependencies

Near it in the frame