Discussing the turret aimpoint Calculation

This forum is the ideal place for all discussion relating to X4. You will also find additional information from developers here.

Moderator: Moderators for English X Forum

Post Reply
User avatar
ubuntufreakdragon
Posts: 5198
Joined: Thu, 23. Jun 11, 14:57
x4

Discussing the turret aimpoint Calculation

Post by ubuntufreakdragon » Fri, 9. Apr 21, 18:50

Currently turrets and main guns calculate their aim points pretty simple by elongating the current speed vector of the target and try to hit it by a projectile of a given velocity.
You can test this is true by strafing circular a bit and looking where the shots go.
This calculation defies several things that effect the aim point like:
The speed of the shooting ship, the speed of the turret due to a rotation of the shooting ship.
The target currently accelerating constantly e.g. launching travel drive.
Evasive Actions of the target.

I will now propose a formula to include all these effects while maintaining an efficient calculation.
Now some Maths.
We will use, Vectors, Coordinate Transformations and Polynomials, so quite simple Math with existing high performance libraries.
We note that our used Polynomials will be compatible to the used Coordinate Transformations, which will allow quite some performance gain later.
First we need this data input:
the current position of the shooting turret 'a'. p_a=(px_a,py_a,pz_a)
the current velocity of the shooting turret 'a'. v_a=(vx_a,vy_a,vz_a)
the velocity of the projectile to shoot. v_c
the lifetime of the projectile to shoot, (this denotes the range of the gun). t_max
the current position of the target 'b'. p_b=(px_b,py_b,pz_b)
the position of the target 'b' i seconds ago. p_b_i=(px_b_i,py_b_i,pz_b_i)
the calculation doesn't even need the targets current velocity but it can be used to speed up the calculation.

1 Our first step is a coordinate transformation, we choose to calculate as if the shooting turret 'a' wont move and is at position (0,0,0):
p_b'=p_b - p_a
p_b_i'=p_b_i - p_a + v_a * i

2 Now we make 3 Polynomial Fits for the movement of the target in the past, one for each coordinate: (there are efficient libraries for that).
P_b'(t)=(Px_b'(t), Py_b'(t), Pz_b'(t))
Due to the compatibility of the Polynomial and the coordinate transformation 1 this can be pre calculated on per target base and transformed.

3 Now we wish to solve P_b'(t) = v_c*direction*t, but this would be to complex, we solve it indirect by using the effects of the coordinate transformation 1.
As the turret doesn't move and stays at position (0,0,0), all that matters is the distance of the target r_b'(t)=||P_b'(t)||_2
We aim to solve r_b'(t)=v_c*t, to make this even simpler we square the calculation to get rid of the euclidean norms sqrt: (r_b'(t))² = (v_c*t)²
This is just finding the first zeropoint of the simple Polynomial (r_b'(t))² - (v_c*t)² = 0 within [0s, t_max] (on the fly we now check whether the target will still be in range)
The polynomial only contains one variable, so the calculation stays very simple, there are again very efficient libraries for this.
The result would be the point in time when the Projectile will hit t_b.

4 All left to do is to insert this time into the Polynomial P_b(t_b) to get the targets position when it's hit.
and calculate the aiming vector v_c' such that v_a and v_c' added up will move through this position.

Caution implementing this might lead to L Plasma sniping S ships.
My X3 Mods

XRebirth, things left to patch:
In General; On Firing NPC's; In De Vries; Out Of Zone; And the Antiwishlist

Post Reply

Return to “X4: Foundations”