How it Works
The turret (A), the player (B) and the point of collision (C) make a triangle. The length of line AC is equal to the speed of the turret's bullet (u) multiplied by the time taken to get to the collision point (t). The length of BC is equal to the speed of the player (v) multiplied by t also.
AC = ut BC = vt
The size of the triangle can be scaled down by a factor of t, meaning that
AC = u BC = v
The turret needs to find the angle towards the collision point (alpha). This can be obtained using Sine Rule. Sine Rule says that:
a b ------ = ------ Sin(A) Sin(B)
Where a is the side of any triangle with opposite angle A, and b is another side of the triangle with opposite angle B. In the case of the player/turret/collision triangle, where all angles are measured from the horizontal, we get:
u v ------------------ = ------------------ Sin(gammaB - beta) Sin(alpha - gammaA)
Where beta is the angle of the player from the horizontal, gammaA is the angle from the turret (A) towards the player (B), and gammaB is the angle from the player (B) towards the turret (A). We can rearrange the Sine Rule equation to get an expression for alpha:
/ v Sin(gammaB - beta) \ alpha = Sin-1 | --------------------- | + gammaA \ u /
The turret uses this equation to calculate the required angle when bullet speed (u), player speed (v), player angle (beta), angle to player (gammaA) and angle from player (gammaB) are all known.