As this was the first result when googling this problem and there isn’t an answer to the exact question, I hope there is no issue posting in this old question.
I had the same issue, and found the solution by illustrating the problem as a triangle:

- Q = our current position,
- P = target current position,
- V1 = target velocity,
- v2 = our velocity,
- z = time from now that intersection will happen,
- FP(z) = position of intersection.
- By || I mean the magnitude of the vector inside.
As you can see, we have an angle and three sides of which two are dependent on z.
We can then use the formula to create an equation:
a^2 = b^2 + c^2 - 2 * b * c * cos(A)
(|V2| * z)^2 = (|V1| * z)^2 + |PQ|^2 - 2 * |V1| * z * |PQ| * cos(angle(PQ, V1))
Note: it is important for the angle that we use PQ and not QP, for the magnitude it doesn’t matter.
After some re-writing, we get a quadratic function = 0 with the coefficients:
- a = |V2|^2 - |V1|^2
- b = 2 *|V1| * |PQ| * cos(angle(PQ, V1))
- c = -(|PQ|)^2
We then use the normal formula for solving a quadratic function = 0 to find z. If there is a possible intersection, then we will get a positive z. Remember to check if a != 0 and that the determinant >= 0 (return a negative number if we can not find a solution).
If we get a positive number, we can use FP(z) to find the position of the intersection. FP(z) is a simple line equation for lines in 3d:
FP(z) = P + z * V1
If we get a negative z, it is up to yourself how to handle this. You might also want to create an upper bound on z, so if the missile is chasing behind the target with a small velocity difference, it isn’t aiming 10km ahead.
Update: One thing I didn’t take into account when writing this answer was that it is possible for two intersections to exist. In that case we will get two positive z values. Choosing the lowest positive z should be the most optimal option (earliest intersection point), but choosing the other is still valid. Just make sure to be consistent between choosing the closest or furthest intersection or you can end up with constantly switching between the points ending up not really reaching either.
This is what I did previously. I tried to take into account the new position and how the distance may have grown wii it iteration. The problem with your sample is that I could think I can hit my target and with the increase in distance from determining where my target is 't' amount of time along its path, and not actually hit it still. Is there a constant way to incorporate this increase in distance when extrapolating the new target position for an extra amount of time?
– 1337GameDevAny other ideas?
– 1337GameDev