Stealth games—pioneered by Hideo Kojima’s original Metal Gear (1987) and elevated by Looking Glass Studios’ Thief: The Dark Project (1998)—represent one of the most sophisticated applications of Sensor Fusion, Ray-Casting Geometry, and Hierarchical Finite State Machines in video game design. Unlike typical action titles where enemy AI locks onto the player omnisciently, a stealth game is fundamentally an information asymmetry puzzle: the player must study, manipulate, and evade imperfect artificial perception systems.
In our action roster, titles like Kunai Shadow Striker, Stealth Agent Shadow, and Shadow Agent Infiltrator demonstrate how discrete sensory cones create tense infiltration gameplay. Understanding the mathematical mechanics of visual ray-casting, acoustic noise propagation, and Last Known Position (LKP) tracking transforms chaotic evasion into tactical infiltration.
1. Visual Perception: Ray-Cast Cones of Vision (FOV)
In game engine architecture, an enemy guard’s eyes are mathematically modeled as a Planar Field of View (FOV) Vision Cone:
2D RAY-CAST CONE OF VISION GEOMETRY
Guard Position (Xg, Yg)
│
├── Heading Vector H
╱ ╲
Angle -θ/2 ╱ ╲ Angle +θ/2
╱ ╲
╱ CORE ╲ (Central Cone: Rapid Detection)
╱ DETECTION ╲
╱ ╲
───────────────────────────┴─────────────────────┴───────────────────────────
Maximum View Distance R_max
The Three Mathematical Visibility Tests
For a guard to visually detect the player at coordinate $(X_p, Y_p)$, the player must satisfy three simultaneous geometric conditions:
- Distance Check: The Euclidean distance between guard and player must not exceed the guard’s maximum visual range $R_{\text{max}}$: $$d = \sqrt{(X_p - X_g)^2 + (Y_p - Y_g)^2} \le R_{\text{max}}$$
- Angular Threshold Check: The angle between the guard’s forward facing heading vector $\vec{H}$ and the vector pointing toward the player $\vec{D} = \text{Pos}_p - \text{Pos}g$ must fall within the half-angle vision cone $\theta / 2$: $$\cos(\phi) = \frac{\vec{H} \cdot \vec{D}}{|\vec{H}| |\vec{D}|} \ge \cos\left(\frac{\theta{\text{FOV}}}{2}\right)$$
- Ray-Cast Line-of-Sight (LoS) Intersection: Even if the player is within range and within the angular cone, the engine casts a straight mathematical ray from the guard’s eye to the player’s center. If the ray intersects any static obstacle (wall, pillar, crate), the ray is blocked: $$\text{Ray}(\text{Guard} \to \text{Player}) \cap \text{Obstacles} = \emptyset$$
2. Graduated Suspicion Meters and Concentric Threat Rings
Early retro games treated detection as a binary switch: the microsecond you entered a guard’s line-of-sight, an alarm sounded and the guard opened fire. Modern stealth design replaces this jarring binary with Continuous Suspicion Accumulation:
CONCENTRIC VISION THREAT ZONES
╭────────────────────────────────────────────────────────╮
│ Outer Peripheral Cone: Suspicion fills at 25% / sec │
│ ╭────────────────────────────────────────────────╮ │
│ │ Central Focus Zone: Suspicion fills at 100%/sec│ │
│ │ ╭────────────────────────────────────────╮ │ │
│ │ │ Instant Kill Zone: Immediate Combat! │ │ │
│ │ ╰────────────────────────────────────────╯ │ │
│ ╰────────────────────────────────────────────────╯ │
╰────────────────────────────────────────────────────────╯
The Suspicion Integral Formula
When the player is visible, an on-screen Alert Gauge ($S$) fills according to an environmental exposure integral: $$S(t) = S_0 + \int \left( K_{\text{zone}} \times K_{\text{light}} \times \frac{R_{\text{max}} - d}{R_{\text{max}}} \right) dt$$
Where:
- $K_{\text{zone}}$ is high ($1.0$) in central vision and low ($0.25$) in peripheral sight.
- $K_{\text{light}}$ is modified by shadow: crouching in darkness drops $K_{\text{light}}$ to $0.10$.
- Distance factor: Being 1 meter away fills the meter $10\times$ faster than standing 10 meters away.
If the player ducks behind a crate before the meter reaches $100%$, the gauge decays smoothly back to zero, allowing the player to remain in the shadows without triggering an alarm.
3. Acoustic Perception: Noise Propagation Spheres
Guards do not only possess eyes; they possess ears. Every physical action performed by the player emits a Radial Acoustic Pulse:
ACOUSTIC NOISE PROPAGATION RADIUS
Action Type Acoustic Radius (R_sound) Guard Reaction
─────────────────────────────────────────────────────────────────────────
Crouch Sneak 0.0 meters Completely Silent
Standard Walk 3.5 meters Guard enters Suspicious State
Sprint / Dash 10.0 meters Instant Head-Turn & Investigation
Throw Shuriken / Kunai 1.5 meters Pinpoint Impact Distraction
Gunfire / Explosive 35.0 meters (Full Map) Global Base Alarm Triggered
[Player Sprints: Noise Ring Expands R = 10m]
│
▼
Guard Coordinate Within Noise Sphere?
│
┌─────────────┴─────────────┐
▼ ▼
YES NO
Calculate Vector Continue Normal
Toward Sound Source Patrol Waypoint
│
▼
Guard Turns Around!
When an acoustic pulse intersects a guard’s coordinates, the guard immediately pauses their patrol waypoint schedule, turns to face the vector of the sound, and walks toward the epicenter to investigate.
4. The 4-Tier Finite State Machine (FSM)
At its computational core, every stealth guard is driven by a Hierarchical Finite State Machine:
[PATROL MODE] ──► (Player Glimpsed / Noise Heard) ──► [SUSPICIOUS MODE]
▲ │
│ (Search Yields Nothing: All Clear!) │ (Meter Hits 100%)
│ ▼
[SEARCH MODE] ◄── (Player Escapes Sight Cone) ── [COMBAT / ALERT MODE]
- Patrol Mode (Unaware): The guard walks along fixed, cyclical coordinate waypoints at low speed. The vision cone is narrow and tinted a calm green.
- Suspicious Mode (Investigating): The vision cone turns yellow. The guard stops, turns toward the stimulus, and cautiously approaches the source of the disturbance with weapon raised.
- Combat / Alert Mode (Hunting): The vision cone turns flashing red. The guard fires at the player, accelerates to sprint velocity, and triggers nearby guards via global radio broadcasts.
- Search Mode (The Last Known Position): If the player breaks line-of-sight and hides, the guard does not give up immediately. The guard sprints to the Last Known Position (LKP)—the exact coordinate where the player was last seen—and searches the immediate perimeter for 10 seconds before returning to normal patrol.
5. Technical Comparison: Perception Systems Across Browser Titles
The following matrix compares AI perception architectures, sensory modalities, and stealth mechanics across action games:
| Stealth / Action Title | Primary Vision Model | Acoustic Detection | Shadow / Lighting Occlusion | Alert State Hierarchy | Benchmark Portal Title |
|---|---|---|---|---|---|
| Kunai Shadow Striker | 2D Line-of-Sight Ray-Cast | Footstep Noise Radii | Dynamic Dark Zone Stealth | 4-Tier FSM (Patrol to Combat) | Kunai Shadow Striker |
| Stealth Agent Shadow | Swept Vision Cones | Silenced Weapon Cues | Wall Shadow Occlusion | Real-Time Suspicion Meter | Stealth Agent Shadow |
| Shadow Infiltrator | Laser Barrier Grids | Terminal Security Tripwires | Stationary Hiding Lockers | Instant Tripwire Alarms | Stealth Infiltrator Laser |
| Retro Maze Man | Pure Coordinate Proximity | Zero (Sightless Tile AI) | Zero (Open Bright Corridors) | Scatter vs Chase State Timer | Retro Maze Man |
| Sokoban Warehouse | Static Obstacle Matrix | Zero (Pure Puzzle) | Zero | Unmoving Wall Collisions | Sokoban Warehouse Puzzle |
6. How to Exploit AI Perception for Ghost Infiltrations
To achieve “Ghost” (Zero Alarms) ratings in Kunai Shadow Striker:
- Abuse the LKP Ghost Marker: When spotted, sprint around a corner, break line-of-sight, and immediately double-back through an air vent or climb onto a high ceiling beam. The guard will focus 100% of their attention investigating the corner where you disappeared, exposing their vulnerable back to a silent takedown.
- Manipulate Heading with Audio Baits: Throw a throwing star (kunai) or pebble against a wall behind a guard. The acoustic pulse will force the guard to turn around $180^\circ$, swinging their vision cone away from the door you need to breach.
- Crouch-Walk to Eliminate Footsteps: Never run in corridors adjacent to guard rooms. Crouching reduces your acoustic radius to zero, allowing you to pass within centimeters of guards behind thin walls.
Frequently Asked Questions
Why do stealth games always let players see enemy vision cones on the mini-map?
In real life, human beings rely on peripheral vision, spatial acoustic audio, and subtle atmospheric clues to sense if they are being watched. On a flat 2D computer screen, conveying these sensory inputs is difficult. Drawing glowing vision cones on the ground provides clear, transparent visual feedback, externalizing the AI’s internal state machine so the player understands the rules of engagement without feeling cheated by invisible sight lines.
What is the “Shadow Stealth” threshold?
In games like Stealth Agent Shadow, specific areas of the map are designated as deep shadows. When the player enters a shadow zone, the engine cuts the guard’s maximum visual range ($R_{\text{max}}$) by up to $80%$. A guard who could normally spot you from 20 meters away cannot see you in a shadow zone until they walk within 4 meters, turning dark alcoves into safe infiltration sanctuaries.
How do modern canvas games calculate dynamic shadow ray-casting at 60 FPS?
Calculating thousands of ray-polygon intersections per second is computationally demanding. Modern HTML5 engines use 2D Visibility Polygon Algorithms: they project rays exclusively toward the vertices (corners) of obstacle polygons rather than every individual pixel. By sorting these corner angles and connecting the intersection points, the engine constructs a geometric 2D visibility mesh that is rasterized in a single GPU pass.