Make enemies see the hero only when no wall is in the way
Enemies that spot you through walls feel like cheating, and the AI's quick check by looking at a few points along the line can miss a thin wall completely. This entry walks along the line cell by cell so that no wall tile can be skipped.
Why this works
Seeing is a question about everything between two points. Checking a few spots along the way trusts the gaps, and thin things hide in gaps. Visiting every cell the line passes, in order, leaves nowhere for a wall to hide.
When not to use it
Skip it when the world is not made of tiles, or when enemies should notice by sound or by being close rather than by sight. Then use a distance check, or ask the engine's own ray test for round and slanted shapes.
In the full entry
- What to build, step by step
- Starting values and the reason for each
- 4 common mistakes and the fix
- 32 lines of example code with 5 checks that pass
- How your AI shows you that it works
Say this to your AI
Use the Spielerando entry "Make enemies see the hero only when no wall is in the way" (read_entry action-sight-line-through-walls) in my game. Build it step by step, and show me how you checked that it works.Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP