integration wrote:In the case, that the AA Gun fires straight flying projectiles (and is no instant hit weapon), I want you to know, that it is possible to calculate where to shoot to hit the Aircraft, if the AirCraft isnot changing its speed nor its moving direction. Of course you would have to rewrite the AdjustAim function.Code: Select all

`In the following for vectors x I use the notation x² = x dot x`

let y (vector) be the target's speed

let z (vector) be the vector from shooter to target

let v (float) be the projectile's speed

let t (float) be the unknown time until the impact

let x (vector) be the unknown normed (x²=1) shooting direction

Then we have: t*v*x = t*y + z

Thus the square of the length of both sides must be the same

(t*v*x) dot (t*v*x) = (t*y + z) dot (t*y + z)

t²*v² = t²*y² + 2*t*(y dot z) + z²

t²*(v²-y²) - 2*t*(y dot z) = z²

This is a quadratic equation in t

With a = v² - y², b = y dot z, c = z² we have

a*t² - 2*b*t = c or rearranged

a*(t - b/a)² - b²/a = c

(t- b/a)² = (c*a + b²)/a² , now take the root

t - b/a = +/- sqrt(c*a + b²)/a

t = [b +/- sqrt(c*a + b²)]/a

So if d := b*b + c*a > 0 we get the 2 solutions

t = ( b + sqrt(d) )/a and t = ( b - sqrt(d) )/a

Use the one with t > 0 and t as small as possible

In the case a > 0 (projectile faster than target)

it should be t = ( b + sqrt(d) )/a

The unknown shooting direction x is Normal(t*y + z)

Interesting. Altrough I don't wanna to changing original actor/object scripts, so projectiles from AA will be instant hit (like in rifle,minigun,CAR). But this code looks interesting. Would you wanna explain a little about it on PM??