leading shots with <OnFireWeapon>

Freeform discussion about anything related to modding Transcendence.
Post Reply
User avatar
digdug
Fleet Admiral
Fleet Admiral
Posts: 2620
Joined: Mon Oct 29, 2007 9:23 pm
Location: Decoding hieroglyphics on Tan-Ru-Dorem

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:
Image
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 :D
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

This is absolutely awesome digdug. An elegant solution.
User avatar
Atarlost
Fleet Admiral
Fleet Admiral
Posts: 2391
Joined: Tue Aug 26, 2008 12:02 am

This isn't a general solution at all. It does not work against flyby AI, nor does it work against anything not attacking you, nor does it work for simulating multitarget="true" fragments.
User avatar
Psycholis
Militia Commander
Militia Commander
Posts: 298
Joined: Sun Mar 05, 2006 8:23 pm
Location: Missouri

i'm not seeing your solution to the problem, atarlost. upload a reasonable alternative and maybe you'll have the credentials to criticize.
User avatar
alterecco
Fleet Officer
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)
User avatar
Atarlost
Fleet Admiral
Fleet Admiral
Posts: 2391
Joined: Tue Aug 26, 2008 12:02 am

Implementing the dot at sufficient resolution requires floating point arithmetic. Using George's algorithm for target leading also requires floating point square root, but with a full set of four floating point arithmetic functions I'm confident I can do that.
User avatar
Psycholis
Militia Commander
Militia Commander
Posts: 298
Joined: Sun Mar 05, 2006 8:23 pm
Location: Missouri

my mistake. just thought it was an out of the blue insult on what i considered a fairly good modding attempt. makes it seem like other people's work isn't considered good enough for some people's standards. disregard then.
Jeoshua
Militia Lieutenant
Militia Lieutenant
Posts: 163
Joined: Sat Sep 06, 2008 3:48 pm

This is probably in the wrong forum, honestly.

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
Post Reply