Line of Sight and Stealth Detection
Stealth works when players can read exactly what the guard can see and hear. Here is the detection model, with numbers, that keeps getting caught fair.

Key takeaways
- Detection is a meter, not a switch: it fills faster when the player is close, lit and moving, and drains slowly.
- Check sight with a cone test, then a raycast against walls to two or three points on the player, a few times a second.
- Show players what guards see and hear, and give suspicion a stage between unaware and alert.
Line of sight in a stealth game is the check that decides whether a guard can see the player: the player must be inside the guard's vision cone (an angle and a range) and no wall may block a straight line between them. Stealth detection builds on it with a meter that fills while the player is seen, faster when they are close or in light, plus noise that guards can hear, and a few guard states between unaware and alert. Fair stealth means the player can always read what the guard perceives.
The vision cone, with numbers
A guard sees in a cone in front of them. Test it in two cheap steps before doing anything expensive: is the player within range, and is the angle between the guard's facing direction and the direction to the player less than half the cone angle? Starting values:
- Main cone: 60 to 90 degrees wide, range about 8 to 12 tiles in a top-down 2D game, or 10 to 15 meters in 3D.
- Peripheral cone: about 140 to 180 degrees, but only 2 to 4 tiles of range, and it fills the meter at a third of the speed. Guards notice someone right beside them, but slowly.
- Close range: within about 1 to 1.5 tiles, the guard notices the player in any direction. Brushing past someone's back should not work.
- Crouching or hiding shortens the effective range, often to half.
- Light: in dark areas, multiply the range by 0.3 to 0.5; under a lamp, use full range.
Only if the player passes the cone test, cast a ray from the guard's eyes toward the player and see whether it hits a wall first. Cast to two or three points on the player (head, center, feet) and count them seen if at least two are visible. A single ray to the center makes players visible through a gap the width of a pixel, or invisible behind a knee-high crate.
A detection meter, not a switch
If being seen meant instant failure, stealth would be a game of perfect information that punishes any mistake. A meter gives players time to react. Each guard has a suspicion value from 0 to 1:
- Fill time at the edge of range: about 1.5 to 2 seconds. Up close: 0.3 to 0.5 seconds. Interpolate by distance.
- Multipliers: moving fast fills it faster (1.5 times), crouching slower (0.5 times), dark areas slower again.
- Drain: 2 to 4 seconds from full to empty once the player is out of sight, starting after a short delay of about 1 second. Draining slower than filling lets guards stay wary.
- Thresholds: above about 0.5, the guard becomes suspicious and investigates; at 1, alert.
Guard states
A small state machine gives guards believable behavior with very little logic. Our enemy AI guide covers state machines in general; for stealth, these five do the work:
- 01Patrol: walk a route of points, pausing and looking around at some of them for 1 to 3 seconds. Pauses are where players slip past, so they are level design, not decoration.
- 02Suspicious: stop, turn toward the stimulus, play a "Hm?" bark. If suspicion keeps rising, walk to the last known position.
- 03Investigate: go to the last known position (not the player's current position, which the guard does not know), look around for 4 to 8 seconds.
- 04Alert: chase or attack, and alert guards within a radius (about 6 to 10 tiles) with a shout. Decide whether this is failure (restart from checkpoint) or a fight.
- 05Search, then return: after losing the player, search nearby for 15 to 30 seconds, then return to patrol, a little more wary (wider cone or faster fill) for a while.
Noise: the other half of detection
Sound lets guards notice what they cannot see, and gives players a tool: throw a bottle to pull a guard away. Treat noise as events with a position and a radius:
- Walking: 1 to 2 tiles. Running: 5 to 7. Landing from a jump: 3 to 5. Breaking glass or a thrown object: 8 to 10.
- Hearing does not need line of sight, but walls should reduce it. A cheap approach: measure noise distance along the navigation path rather than in a straight line, so sound goes around corners and not through thick walls.
- Noise raises suspicion and gives a position, sending guards to investigate where the sound came from, not where the player is.
- Show noise as rings expanding from the player's feet, sized to the actual radius. It teaches the rules instantly.
Bugs and unfair moments
- Seen through corners. The ray starts at the guard's center and grazes a wall corner. Start rays from the guard's eye point, and shrink wall colliders slightly for sight checks, or use the multi-point rule.
- Instant turn detection. A guard turns 180 degrees in one frame and fills the meter at point blank range. Limit turn speed (about 180 to 270 degrees per second) and telegraph turns with a short pause.
- Performance. Ten guards casting three rays every frame adds up on phones. Run sight checks 5 to 10 times a second per guard, staggered so they do not all run on the same frame, and skip guards far off screen.
- Doors and glass. Decide whether windows block sight (usually not) and whether closed doors block sound (partly). Keep separate collision layers for movement, sight and sound.
- Alert chains. One guard alerts another who alerts another until the whole level is chasing. Alerting should not cascade more than once.
- Hiding spots that do not hide. If a player is in a locker or a bush, sight checks must skip them unless a guard watched them enter.
Show the player what guards perceive
Stealth is only fun when players can predict outcomes. In top-down games, draw each guard's vision cone on the ground, clipped by walls, faintly in the patrol state and stronger as suspicion rises. In 3D, cones on the ground are often too much; use the suspicion icon, a clear facing (a flashlight beam helps), and audio barks for every state change. Our horror game guide covers the opposite case, where hiding what the enemy perceives is the point.
Level layout does the rest: patrol routes that cross, pauses that open windows, shadows and cover placed so there is always at least one route. The level design basics apply directly; in Startbase you can move cover, lamps and patrol points by hand in the World Editor and replay the room at once.
Combining stealth with other mechanics
- With light: lamps the player can switch off are the classic stealth tool. Each one changes the detection range in its area.
- With distractions: throwables create noise events at a chosen point.
- With takedowns: approaching from behind while the guard is unaware allows a quiet takedown; bodies found by other guards raise suspicion.
- With score: rewarding undetected runs (a ghost bonus) makes stealth a choice, not a requirement.
A brief for stealth detection
Add stealth to my top-down 2D game. Each guard has a 70 degree vision cone with 10 tile range, a 160 degree peripheral cone with 3 tile range that fills at a third of the speed, and notices anyone within 1 tile. A cone test runs first, then rays from the guard's eyes to the player's head, center and feet; two visible points count as seen. Checks run 8 times a second, staggered. A suspicion meter fills in 1.8 s at max range down to 0.4 s up close, 1.5x when running, 0.5x crouching or in darkness, and drains over 3 s after a 1 s delay. States: patrol, suspicious, investigate last known position, alert (shouts to guards within 8 tiles), search for 20 s, return. Draw vision cones clipped by walls and suspicion icons over guards. Running makes 6 tile noise rings.
Frequently asked questions
How does line of sight work in games?
The game checks whether the target is inside the viewer's vision cone (an angle and a range), then casts a ray from the viewer's eyes toward the target. If a wall is hit first, the target is not visible.
How wide should a guard vision cone be?
Around 60 to 90 degrees for the main cone with a range of about 8 to 12 tiles in top-down games, plus a wider, short peripheral cone that detects more slowly.
How do I make stealth feel fair?
Use a detection meter instead of instant failure, show each guard's suspicion and vision, cast rays to several points on the player, limit how fast guards turn, and make sure every room has a route through.
How do guards hear the player?
Treat noises as events with a position and a radius, raise suspicion for guards within the radius, and send them to investigate where the noise came from. Measuring distance along paths makes sound go around corners.

