The white part represents the “lead”, or how far ahead the turret will shoot so that the shell hits the ship properly. The code uses an iterative algorithm to find how far ahead to shoot, I did it this way to avoid really complex maths.
Feels a bit unfair though, the angle it shoots is perfect every time, although the lead assumes you aren’t turning at all and that your moving at a constant speed, so steering into the turret and accelerating can make it miss, which is quite fun to pull off.
I already had a turret model from the player’s ship, as well as code for actually firing the projectiles and aiming the gun, so I ended up reusing them.
However, for the actual turret, I think everything including:
Calculating angle to fire at
Calculating lead iteratively
Modifying the aim method to give it a “firing angle” as opposed to a mouse position
took around 2 hours? Something like that. Most of that time was spent just figuring out a solution, rather than actually programming it.