Quick answer: After the range and angle test passes, fire a raycast from the eye to the target against the world collision layer and only register detection if nothing blocks it.

Guards spotting you through a solid wall feel broken because the perception code stops at the view cone. Adding an occlusion raycast as the final gate fixes it. Here is how.

How to fix it

1. Gate detection on a LOS raycast

Only after range and view-cone checks pass, raycast from the AI's eye position to the target's center against an environment/occluder mask; treat a blocked ray as not visible.

2. Cast from the eye, not the feet

Use an eye-height origin and aim at the target's chest/head. Casting from foot to foot can clip under or through cover and produce false hits or misses.

3. Add multiple sample points

Raycast to several points on the target (head, torso, feet). Visibility of any one point counts as seen, which avoids flicker when only part of the target peeks out of cover.

Catching the ones you can't reproduce

The hardest version of this to fix is the one you can't reproduce — it only happens on a player's hardware, OS, driver, or save state, under conditions that simply aren't present on your machine. A report that says “it crashed” or “it froze” gives you nothing to act on, so the bug survives release after release while quietly costing you players.

Automatic error capture closes that gap. Each failure arrives with its full stack trace, the device and OS, the build number, and a breadcrumb trail of what the player did right before it broke, so even a failure you have never seen becomes a specific, reproducible issue. Fold identical failures into one signature ranked by how many players each hits, and your worklist sorts itself worst-first instead of arriving as a stream of vague complaints.

This is where a tool like Bugnet earns its place. Its SDK captures every error automatically with the full stack trace plus device, OS, memory, build, and game-state context, folds duplicates into one grouped issue with an occurrence count, and ties each to the build it first appeared on — so you fix the problem that hurts the most players first and confirm it is gone when its signature disappears from the next release.

Most of the time the fix is small. Seeing the failure clearly is the part that actually costs you.