Guide
Game enemy leash and patrol systems explained
Harbor Dockyard’s Act 1 stealth route failed playtests because dock guards chased players across the entire map. A single spotted runner pulled four patrols into the warehouse district, blocking the intended infiltration loop for twelve minutes while enemies slowly walked home. After separating alert radius (who cares that you exist) from leash radius (how far they will pursue) and rebuilding patrols as closed waypoint loops with explicit return paths, ghost-route completion time dropped from 18 minutes to 9 minutes and combat-avoidance satisfaction rose from 41% to 78% in post-level surveys.
Leash and patrol systems define where NPCs are allowed to fight, how they move when idle, and what happens when the player kites them out of position. They are the invisible geometry that makes stealth routes fair, open-world zones readable, and MMO trash pulls predictable. This guide covers tether points, chase and reset radii, waypoint and spline patrols, return-to-path finite-state machines, coordination with AI perception and threat tables, the Harbor Dockyard refactor, a technique decision table vs static guards and random roam, pitfalls, and a production checklist — complementing our stealth mechanics explainer.
Leash vs patrol: two problems, one pipeline
Designers often conflate these; engines should not.
- Patrol answers “where does this NPC go when calm?” Waypoints, splines, or schedule-driven routes sell a living space and create timing windows for stealth.
- Leash answers “how far from home may this NPC pursue?” A tether point (spawn, patrol centroid, or squad anchor) plus a maximum chase distance caps combat spillover.
- Reset answers “when does the NPC forgive and heal?” Dropping aggro, teleporting the last few meters, refilling health, and clearing alert state must be explicit rules — not accidental side effects.
Patrol without leash produces marathon chases. Leash without patrol produces
statues that snap back unnaturally. Production systems wire both into a single
behavior tree or FSM with shared blackboard keys:
home_position, patrol_index, chase_target,
leash_broken.
Core leash parameters
Tether point
The anchor used for distance checks. Common choices:
- Spawn point — simple, works for arena adds.
- Patrol centroid — average of waypoint loop; fair for roaming guards.
- Squad leader position — escort packs share one leash.
- Zone volume center — large outdoor camps use a trigger volume instead of a point.
Chase radius vs leash radius
Split these for readable stealth:
- Alert / aggro radius — entering combat or suspicion. Often smaller than full vision cone reach when combined with noise detection.
- Hard leash radius — absolute maximum pursuit distance from tether. Beyond this, enemy must abandon chase and reset.
- Soft leash warning — optional band (e.g. 80% of hard leash) where AI plays bark lines, slows, or calls reinforcements inside the zone instead of crossing the border.
Reset behaviors
When leash breaks or line-of-sight is lost beyond a timeout:
- Run home — visible return; player can re-engage during transit (risky but honest).
- Fade and snap — despawn off-screen, respawn at tether at full health. Fast but can feel cheap if overused.
- Walk back on patrol path — rejoin nearest waypoint; best for immersion if navmesh supports it.
- State cleanup — clear alert level, re-arm traps, close doors, restock consumables if your design requires it.
Document whether health refills on reset. Players learn the rule quickly; changing it mid-game reads as a bug.
Patrol path archetypes
Closed waypoint loops
Ordered nodes A→B→C→A. Guards pause at nodes (look-around animation, 2–4 s idle) to create stealth windows. Loop direction can alternate per instance so two guards do not stack on the same node.
Ping-pong segments
A↔B along a corridor. Cheap to author; predictable for players after one observation cycle. Good for tutorials, weak for replayable stealth.
Spline or navmesh follow
Continuous paths along docks, walls, or catwalks. Smooth motion but harder to debug timing; sample pause points explicitly rather than relying on corners alone.
Schedule-driven patrol
Ties into NPC daily schedules: guard walks route only during night shift, sits at tavern by day. Leash tether moves with the schedule segment.
Investigation detours
On partial alert, NPC walks to last-known player position, searches 5–8 m
radius, then returns to patrol_index rather than teleporting. This
bridge state is where most “AI feels dumb” bugs live — invest in
return-path queries early.
Chase and return FSM
A minimal state machine that covers 90% of action games:
- Patrol — follow waypoints at walk speed; perception scans active.
- Suspicious — heard noise or glimpsed partial target; move to stimulus, search timer starts.
- Combat / chase — full aggro; path toward target at run speed; leash distance checked every tick.
- Leash break — target too far or unreachable; play abort bark; transition to return.
- Return — path to
home_positionor resume waypoint; invulnerable optional during return to prevent snipe abuse. - Reset complete — health refill per design; alert cleared; re-enter Patrol at saved index.
Edge cases to wire explicitly: player dies during chase (reset or hold aggro on corpse?), elevator moves target vertically (3D leash cylinder vs sphere), mount speed exceeds patrol run speed (extend hard leash or dismount zone).
Zone boundaries and social aggro
Open worlds stack leashes at multiple scales:
- Per-NPC leash — guard won’t leave the dock.
- Camp leash volume — any enemy inside volume shares reset when volume empties of players.
- Region boundary — crossing into town disables hostile AI or triggers guard backup from static NPCs.
Linking matters: spotting one guard should not pull distant
patrols unless they share an alert group ID. Broadcast alert to same
squad_id within 25 m, not to every enemy in the cell.
For MMO-style overworld mobs, leash often pairs with evade — mob runs back at 200% speed, heals to full, and clears threat table. That is a specialized case of return + reset tied to threat systems, not generic patrol AI.
Implementation notes
- Distance metric — horizontal XZ distance ignores vertical cheese (ledge kiting). Use cylinder leash for multi-floor atriums.
- Navmesh reachability — if chase target is across a gap, fail path early and leash-break instead of orbiting the edge for 60 s.
- Performance — patrol tick can run at 4–10 Hz; leash check only in combat states. Stagger waypoint arrivals so ten guards do not pathfind same frame.
- Debug draw — render tether, hard leash, alert radius,
and patrol polyline in editor; QA filters by
squad_id. - Networking — server owns leash break; clients predict chase but snap on reset to avoid desync ghosts chasing empty air.
- Level streaming — persist
patrol_indexand alert state per cell unload; or accept reset on stream-out for low-priority mobs.
Harbor Dockyard refactor (worked example)
The stealth level shipped in three passes:
- Radius split — alert cone 14 m, hard leash 22 m from patrol centroid. Guards bark at 18 m but turn back at 22 m even if the player keeps shooting. Stopped cross-district train pulls.
- Loop patrols — four dock loops (6–8 nodes each) with 3 s lookouts at crane bases. Staggered phase offsets so at least one blind spot exists per minute on each route.
- Return on path — leash break triggers run to nearest waypoint forward on loop (not straight-line snap). Added 4 s invuln during return so players cannot farm free shots; reward is ghost rating, not DPS.
Metrics after patch: average ghost clear 9.2 min (was 18.1 min), combat detection rate unchanged at 34% (intentional — stealth still risky), player reports of “guards followed me forever” dropped 91%.
Technique decision table
| Approach | Prefer when | Avoid when |
|---|---|---|
| Tight leash + loop patrol | Stealth infiltration, contained arenas, fair retry loops | Boss fights need room to kite; vast plains feel artificial |
| Static guard posts | Doorways, turrets, chokepoints; readable sightlines | You need timing puzzles; player boredom on repeat routes |
| Random roam in volume | Wildlife, dungeon filler, low-stakes mobs | Stealth timing critical; QA cannot reproduce failures |
| No leash (zone-wide aggro) | Boss rooms, invasion events, PvP arenas | Open-world quest hubs; players lead mobs to vendors |
| Evade + full heal reset | MMO overworld, risk/reward grinding spots | Single-player narrative where wounded enemies should stay hurt |
Common pitfalls
- One global leash radius — bruisers and snipers need different caps; snipers should hold position at balcony tether.
- Leash > player escape tools — if dash + mount always outrange leash, combat is optional with no tension. Tune against your fastest legal escape.
- Silent snap reset — enemy pops to full health with no animation; players call it a glitch. Show run-back or a brief dissolve.
- Patrol nodes in player cover — guards stop inside stealth grass; move nodes 1 m off hide spots.
- Alert chain reaction — whole map wakes on one bottle throw; limit broadcast radius and line-of-sight for raised alarms.
- Unreachable tether — home point inside geometry after destructible change; validate tether on level save.
- Vertical leash ignored — player on roof, melee mob jumps forever; use cylinder leash or give ranged fallback.
- Quest NPCs share combat leash — escort quest giver chases bandits off a cliff; separate civilian AI profile.
Production checklist
- Define tether type (spawn, centroid, volume) per enemy archetype before greybox.
- Split alert radius, soft leash warning, and hard leash; document in data sheet.
- Author patrol loops with timed idle beats; stagger phases across instances.
- Implement return-to-waypoint path, not only straight-line home.
- Specify reset rules: health refill, threat clear, trap re-arm, invuln window.
- Cap alert broadcast by
squad_idand distance; log chain reactions. - Use horizontal cylinder leash for multi-floor spaces.
- Debug-draw radii and patrol polylines in QA builds.
- Playtest kiting with max-speed mount, dash, and teleport escape items.
- Telemetry: leash break rate, average chase distance, reset reason codes.
Key takeaways
- Patrol sells life; leash sells fairness — they solve different design problems and should be authored together.
- Split alert radius from hard leash so stealth has a teachable risk band.
- Return along patrol paths reads better than invisible snap, even if it costs navmesh work.
- Harbor Dockyard cut ghost clears nearly in half by capping pursuit at 22 m and rebuilding loop patrols.
- Broadcast alerts sparingly — chain reactions destroy otherwise solid stealth routes.
Related reading
- Game AI perception explained — vision cones, hearing, and search states that trigger chase
- Game threat and aggro systems explained — hate tables and tank swaps in group combat
- Game stealth mechanics explained — detection meters and ghost scoring
- Game footstep and noise detection systems explained — audio stimuli that pull patrols off-route