Line of sight and aggro
Enemies notice you only when they could really see you.
Enemies that know where you are through walls feel like cheaters. Real detection has three checks: are you close enough, are you inside the view cone, and is there a clear line from their eyes to you. Add an awareness meter that fills while you are seen, and stealth becomes possible.
Try this: Sneak behind the walls past the guard. Then press L to switch off the wall check: it sees you through walls.
view conesight rayalert
Sneak to the coin without filling the meter.
Prompt bit
Works for 2D or 3D in any engine (Unity, Unreal, Godot, web). Paste the short one for a quick fix, or the detailed one when you want it done properly.
Give enemies real line of sight: detect the player only within 8 units, inside a 90 degree cone and with an unblocked raycast from the eyes, then fill awareness over 0.5 s instead of alerting instantly, so brief glimpses never trigger aggro.
Add enemy perception with line of sight and an awareness meter (2D or 3D, any engine). Each enemy checks a few times a second (every 0.1 to 0.2 s, staggered, not every frame): distance to the player under viewDistance (default 8 units), angle between its forward and the direction to the player under half of viewAngle (default 90 degrees total), and a raycast from its eye position to the player's chest that hits the player first (use a layer mask with walls and the player only). When all three pass, raise awareness by dt / timeToNotice (default 0.5 s, faster when closer); otherwise lower it slowly. At 1, switch to Chase and remember the last known position; when sight is lost, go to that position and search for a few seconds before returning to Patrol. Add hearing as a separate radius for noises such as running or gunshots. Let alerted enemies tell nearby allies. In 2D side-view games ignore the cone and use facing direction. Draw the cone and rays in debug.
Where it's used
- Stealth games: view cones, awareness meters and last known position
- Shooters: enemies that only fire when they can see you
- Top-down and roguelikes: fog of war and room-based aggro
- Survival and horror: monsters that hunt by sight and sound
- Towers and turrets: target only what is in the clear
Common mistakes
Distance-only aggro (enemies see through walls), raycasting from the feet or into the player's own collider, checking every enemy every frame, and instant alerts that make stealth impossible.
Writing this with an AI assistant? See our best AI coding assistants for game developers.
Missing a concept? Request one.



