Work out the angle for a shot that bounces off a wall to hit a hidden target
Some shots ricochet, and an AI that aims straight at its target would never use that. Here is the mirror trick that gives the aim in one step, plus the checks that stop it from picking a bounce point that is not actually on the wall.
Why this works
A bounce off a flat wall behaves like a straight line through a mirror. Reflect the target across the wall and the shot is one straight line to its copy, and the place where that line meets the wall is where the real shot turns.
When not to use it
Don't use it for rough, curved or moving walls, or for shots that lose speed or spin at each bounce, since the mirror picture no longer holds. Several bounces need one mirror per wall. If a plain line works, skip the trick.
In the full entry
- What to build, step by step
- Starting values and the reason for each
- 5 common mistakes and the fix
- 17 lines of example code with 4 checks that pass
- How your AI shows you that it works
Say this to your AI
Use the Spielerando entry "Work out the angle for a shot that bounces off a wall to hit a hidden target" (read_entry bounce-a-shot-off-a-wall-to-hit) 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