Turret - Leads shots and accounts for gravity

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.

2 Likes

I think it looks great. No need to change anything unless you want to make it a bit more realistic(?)

1 Like

This turret looks great! Nice job on it! How long did it take for you to create it?

1 Like

Wow, looks really good so far! I’m now interested in the end product of this :eyes:

1 Like

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.

I should have a demo up within the next few days or so, I’ll make another forum post about it.

Nothing too fancy though, only been working on this for a ~week or so.

2 Likes