Shoot bullet at moving object

 from Red Blob Games
DRAFT
Mar 2017, then Sep 2023

Background: After watching a @ShellSphinx[1]'s GDC talk about projectiles (see slides [PDF[2]]), @SquirrelTweets[3] suggested an interactive diagram version.

Problem: you're trying to a shoot a moving target. If you aim at where they are now, they'll have moved. So you aim ahead of where they are. But your bullet takes longer to get there. Which means you need to aim even farther ahead. How do you calculate this?

Try choosing the angle of fire:

Angle: {{angle_deg}}°

Did you undershoot? Did you overshoot? Or did you get it just right? It kind of feels like a guessing game.

For every angle we can figure out whether we'll undershoot or overshoot the target's line. That's the red line:

Time:
{{ status }}

It's a WEIRD shaped line! It shows where the projectile would be if fired at a given angle. It shows where you'll undershoot vs overshoot. I don't understand this shape.

Try dragging the line endpoints around to see the red line change. There can be zero, one, or two intercept points.

Note: I would've formulated this problem differently from the way it was presented at GDC. I think of this as cone-ray intersection; math is here[4] and it might be useful to try that to see if I get the same answers as presented in the talk.

Also see https://web.archive.org/web/20230325051511/http://howlingmoonsoftware.com/wordpress/leading-a-target/[5]

Source: interception.js