The problem:

Omnidirectional turrets shoots at a leading position, <OnFireWeapon> does not provide the math done by omnidirectional code (as George showed us the code long time ago: http://wiki.neurohack.com/transcendence ... obably_old)

So, slow firing omnidirectional <OnFireWeapon> are useless.

I have a good working example of code that provides leading shot angles for omnidirectional turrets with <OnFireWeapon>.

Even with the approximations, the code works well enough to shot down a Hornet (fastest ship in the game) with a speed 40 weapon. (average kinetic or missile slow weapon)

The math:

Let's consider a triangle as in figure:

a= distance traveled by the target ship, when the projectile will hit it.

b= distance between source-target

We have to predict the position of the Hornet, this is done with an approximation: we consider that the distance of the Hornet will remain nearly the same when the projectile will reach it.

so the time will be t=b/Vp

where V is the velocity of the projectile

we then multiply this time by the speed of the target Vt

Vt*t= a

we now have a !! (with an approximation)

we can now do the trigonometry

arctan(a/b)=theta, that is the angle we need !

the arctan function has been found on a website that resolved the problem with a polynomial approximation that works for small numbers and returns the number in degrees (exactly what we need)

Finally we just sum the resulting angle with the angle of the aFireAngle given by the <OnFireWeapon> and we have a fully working leading shot! (you can barely see the shot circled in red in the image, sorry, that's the best screenshot i could take)

The mod!

I uploaded the example code here:

http://xelerus.de/index.php?s=mod&id=709

Have fun tinkering with it

## leading shots with <OnFireWeapon>

- alterecco
- Fleet Officer
**Posts:**1658**Joined:**Wed Jan 14, 2009 3:08 am**Location:**Previously enslaved by the Iocrym

What digdug has made is very nice and works for some cases, but Atarlost raises some real valid points. It is currently not realistic to achieve the goals Atarlost state, so what we are also asking for is the tools (scripting tools) to achieve it. In particular we need to be able to calculate the dot product of two vectors to do some of the advanced target leading. I guess the reason Atarlost reponds here very briefly is that a lot of the conversation has been taking place on irc, and we have all been going over this in detail (digdug, atarlost and myself)

Good job tho. I'm still trying to wrap my head around the LISP-like scripting language, and all the math involved in modding here. This should help with some stuff I've been struggling to understand. Thanks dig