# Finding the best angle of movement to cause a line-intersection.

I am working on developing a simple Turret for a personal game project that I've been working on and found myself in need of a formula for detecting the proper angle to fire a projectile in order to hit a moving target.

I have been looking at the line-intersection formula for awhile, however it doesn't take time into consideration at all.

The idea here is that I have two points on a graph. The first point (P1) being the player and the second point (P2) being the Turret.

We know the following information about P1:

• Current x & y coordinates.
• The direction it's moving in.
• The amount of "units" per second it's moving.

We know the following information about P2:

• Current x & y coordinates.
• The amount of "units" per second the point can travel.
• The maximum range that can be traveled.

What we need to find about P2:

• The most optimal direction to travel to intersect with P1 at the earliest possible time.

Here's a more simplified example

P1 is at (200, 400) moving 45degrees at 250 units per second.
P2 starts at (180, 280) and can travel 900 units per second for a maximum of 1300 units.


What direction should P2 travel in order to intersect with P1 in the shortest possible time / distance.

These values are constantly changing every frame, so any help pointing me towards what formula's I need to be using or an in-detail explanation of how to calculate this would be extremely appreciated.

BONUS: Even though P1 and P2 are bound to a single position on the "grid" they both have a size, for example P1 may be 80 units wide and P2 may be 30 units wide, how could I include this in the calculations required to determine the best possible direction.

NOTE: I'm not just simply looking for an answer, please provide reading material on this as-well if possible, or even KHAN Academy videos. I've been searching for a few days now and I've watched tons of video on angles and line intersection but I still don't understand this and really need to.

• check this Wikipedia article, it has a lot of info, including picking an angle to hit a point with $(x, y)$ coordinates: en.wikipedia.org/wiki/Projectile_motion – Vasya Apr 7 at 21:40
• @Vasya Awesome, thanks. Any additional material you have I'm glad to take. – Christian Tucker Apr 7 at 21:50
• Check also this resource which has pretty good explanations regarding firing a projectile: school-for-champions.com/science/… – Vasya Apr 7 at 21:54