To intercept a moving target with a projectile, you must know the velocity and current position of the target, as well as the speed of the projectile and its point of origination (the position of the shooter). For this method, the speed of the projectile and the velocity of the target may be arbitrary, but they must be constant and not subject to acceleration.
At the exact moment when both the target and the projectile have reached the same distance away from the shooter, they have the potential to intersect if the projectile was fired in exactly the right direction. To find this direction, we must solve for the time t at which they have the potential to intersect, then plug that time into the target's position function to find out exactly where the target will be when the bullet will have moved just far enough to run into it.
Recall that the magnitude of a position vector is its scalar distance from the origin. The projectile's scalar distance is represented by the function:
That is, the distance it has moved by time t is its speed multiplied by the time elapsed plus the distance it has “already” traveled (its starting position).
To solve for the time of potential intersection, we must convert the target's vector position function into a scalar distance function, which we can then set equal to the projectile's own scalar distance function.
As you can see, the equation simplifies into quadratic form. To solve for the time of intersection (discarding the negative result), we use the quadratic formula.
If there is no positive result, there is no solution (the target is too fast for the projectile to catch up with it). Once the time t is found, it may be used to determine the exact direction to aim the projectile at.