skip to content

How should a stealth guard's detection meter work so a crouched player in shadow at the edge of vision is noticed gradually?

level: middleimportance: nice to knowfreq 42%

answer

  1. a rate, not a yes or no
  2. multiply the modifiers
  3. fraction of body points visible
  4. fill fast, drain slowly
  5. thresholds raise alert levels

basics

~20 s

The meter fills each tick at a base rate multiplied by factors for distance, angle from the gaze, light, stance, movement and visible body fraction, drains when the player is unseen, and crosses thresholds that raise the guard's alert level.

solid answer

~50 s

Detection becomes a **rate** instead of a verdict. Each perception tick the meter rises by `baseRate * distance * angle * light * stance * movement * visibleFraction * dt`, each factor between 0 and 1: farther, further off-axis, darker, crouched, still and half-hidden all slow it. `visibleFraction` comes from sight rays to several body points, spread across frames so many guards stay affordable. When no point is visible the meter waits briefly and then drains more slowly than it fills, so a player flickering behind fence posts does not reset it. **Thresholds** on the meter raise the alert level: suspicious, then searching, then full alert, and after a search the level settles to a watchful baseline rather than fully calm. Multiplying many factors collapses the rate quickly, so each factor needs a floor and the whole thing is tuned against test cases.

go deeper

for a junior

Recall that detection is a meter that fills at a rate shaped by distance, angle, light, stance and movement, and that thresholds raise alert levels.

for a middle

Write the fill formula, compute a rate for a concrete situation, and explain drain, grace delay and how visible body points feed the rate.

for a senior

Diagnose reports such as instant detection, resets behind fences or invisibility in darkness at point-blank range, and budget the rays for a room of guards.

for a principal

Treat the meter as a readable promise to players: decide what it shows on screen and which factors a tuning pass may change without breaking that promise.

## Why a meter instead of a yes or no A pure visibility test answers "seen or not" instantly. In a stealth game that feels unfair: a player who steps into the very edge of a guard's view in deep shadow is caught at once. A **detection meter** turns perception into a quantity that builds over time, so the player gets warning and a chance to retreat, and the guard's reaction is readable. ## The fill-rate formula Each perception tick, with time step `dt`: `meter += baseRate * fDistance * fAngle * fLight * fStance * fMove * visibleFraction * dt` Every factor lies between 0 and 1. A worked example, with all figures invented for illustration and a meter that triggers full alert at 1.0: - A player standing in the open at 10 m of a 30 m range, centred in the gaze, fully lit and fully visible: with a linear distance factor `1 - 10/30`, about 0.67, and every other factor 1, the rate is about 0.67 per second, so full detection takes about 1.5 seconds. - The same guard and a crouched player in shadow at 20 m, near the edge of the cone: distance `1 - 20/30`, about 0.33; peripheral angle 0.3; shadow 0.25; crouched 0.5; creeping 0.8; three of five body points visible, 0.6. The product is about 0.006 per second, so detection would take nearly three minutes. The second figure shows why multiplication needs care: six modest factors collapse to almost nothing, and six factors of 0.5 give `0.5^6`, about 0.016. Designers give each factor a floor, merge related factors, and tune from a table of test situations rather than by feel. ## Measuring the inputs - **Distance**: a falloff from full sensitivity near the guard to zero at sight range. - **Angle**: full inside a central cone, reduced in a peripheral band. - **Light**: a light value sampled at the player's position, taken from lighting the game already computes or from designer-placed light volumes. - **Stance and movement**: crouching, creeping and standing still lower the factor; standing upright and sprinting give the full value. - **Visible fraction**: the share of body points with clear line of sight. ## Sampling body points across frames Testing head, chest, hands and feet gives a partly hidden player partial visibility. Cast every point for every guard every frame and the cost explodes: 40 guards, 5 points and 60 frames a second is 12,000 rays a second. Instead only guards whose range and cone tests pass cast at all, each tests one point per frame in rotation, and the last result per point is kept. If 8 of the 40 guards pass, that is 480 rays a second, and the visible fraction lags by a few frames at most. ## Alert levels and decay | Level | Entered when | Typical feedback | |---|---|---| | Unaware | Meter empty | Routine behaviour | | Suspicious | Meter passes a low threshold | Guard turns, comments, looks closer | | Searching | Meter passes a higher threshold, or a strong noise is heard | Guard investigates the last known position | | Alert | Meter full while the player is visible | Combat or alarm | The guard's behaviour at each level belongs to its decision model; perception owns the meter and the level. Levels fall back over time, but usually to a watchful baseline with a higher base rate rather than to unaware. ## Tuning and common defects 1. **Instant detection** at the edge of view: a binary test, or a base rate so high the factors never matter. 2. **Resets behind fence posts**: the meter empties the moment a ray is blocked; add a short grace delay and a slower drain. 3. **Invisible in shadow at point-blank range**: the light factor reaches zero; give it a floor, or let a close-range factor override it. 4. **Frame spikes**: every guard casts every ray every frame. Showing the meter to the player as an on-screen indicator turns these rules into something the player can learn, which is most of what makes a stealth system feel fair.

  • Why does multiplying many factors make a detection meter hard to tune?
    A product shrinks fast: six factors of 0.5 give 0.5^6, about 0.016, so a player who is only somewhat hidden on every axis becomes nearly undetectable. One factor at zero, such as total darkness, cancels everything else, even at point-blank range. Floors on each factor, fewer merged factors, and tuning against a table of concrete situations keep the result predictable.
  • How do you stop the meter from resetting when the player passes behind fence posts?
    Do not drain on the first blocked ray. Wait for a short grace period with no visible point, then drain at a slower rate than the meter fills. Keeping the last result per body point for a few frames also smooths over gaps that are only a post wide.
  • Where should the alert level settle after a search finds nothing?
    Usually above where it started: the guard returns to its routine but with a higher base detection rate or a wider cone for a while. Dropping straight back to unaware makes guards look forgetful, while staying at search level forever makes the stealth loop unwinnable.

  • Detect the player as soon as one ray reaches any body point.
  • Reset the meter to zero the moment the player leaves sight.
  • Cast rays to every body point for every guard every frame.
  • More multiplied factors always make detection more realistic.
  • After a search the guard should become fully unaware again.
  • Light can be ignored because the vision cone already decides visibility.