Profile image

Perfectly-ish Accurate Auto-Aim

1,327 InvisibleMan  1.3 years ago

I made some Targeting FTs that you can put down on a turret that compensates not only for the target being better than you and actually moving, but also the fact that you didn't properly level out when you started shooting.

Currently doesn't (and may never) work with the Cannons.

How to use

Simply convert every instance of GUN_SPEED to the muzzle velocity of your desired gun OR add a setter FT with the muzzle velocity in it

The Goods

Turning:

atan2(((TargetDistance * cos((TargetElevation + rate(TargetElevation) * 
(TargetDistance / GUN_SPEED))) * sin((repeat((TargetHeading - Heading) + 
rate(TargetHeading) * (TargetDistance / GUN_SPEED)  + 180, 360) - 180))) * 
cos(-RollAngle) - ((TargetDistance * sin((TargetElevation + 
rate(TargetElevation) * (TargetDistance / GUN_SPEED)))) * cos(-PitchAngle) + 
(TargetDistance * cos((TargetElevation + rate(TargetElevation) * 
(TargetDistance / GUN_SPEED))) * cos((repeat((TargetHeading - Heading) + 
rate(TargetHeading) * (TargetDistance / GUN_SPEED)  + 180, 360) - 180))) * 
sin(-PitchAngle)) * sin(-RollAngle)), ((TargetDistance * cos((TargetElevation + 
rate(TargetElevation) * (TargetDistance / GUN_SPEED))) * 
cos((repeat((TargetHeading - Heading) + rate(TargetHeading) * 
(TargetDistance / GUN_SPEED)  + 180, 360) - 180))) * cos(-PitchAngle) - 
(TargetDistance * sin((TargetElevation + rate(TargetElevation) * 
(TargetDistance / GUN_SPEED)))) * sin(-PitchAngle))) / 180

Elevating:

asin((((TargetDistance * sin((TargetElevation + rate(TargetElevation) * 
(TargetDistance / GUN_SPEED)))) * cos(-PitchAngle) + (TargetDistance * 
cos((TargetElevation + rate(TargetElevation) * (TargetDistance / 
GUN_SPEED))) * cos((repeat((TargetHeading - Heading) + 
rate(TargetHeading) * (TargetDistance / GUN_SPEED)  + 180, 360) - 180))) * 
sin(-PitchAngle)) * cos(-RollAngle) + (TargetDistance * cos((TargetElevation +
 rate(TargetElevation) * (TargetDistance / GUN_SPEED))) * 
sin((repeat((TargetHeading - Heading) + rate(TargetHeading) * 
(TargetDistance / GUN_SPEED)  + 180, 360) - 180))) * sin(-RollAngle)) / 
sqrt(pow(((TargetDistance * cos((TargetElevation + rate(TargetElevation) * 
(TargetDistance / GUN_SPEED))) * sin((repeat((TargetHeading - Heading) + 
rate(TargetHeading) * (TargetDistance / GUN_SPEED)  + 180, 360) - 180))) * 
cos(-RollAngle) - ((TargetDistance * sin((TargetElevation + 
rate(TargetElevation) * (TargetDistance / GUN_SPEED)))) * cos(-PitchAngle) + 
(TargetDistance * cos((TargetElevation + rate(TargetElevation) * 
(TargetDistance / GUN_SPEED))) * cos((repeat((TargetHeading - Heading) + 
rate(TargetHeading) * (TargetDistance / GUN_SPEED)  + 180, 360) - 180))) * 
sin(-PitchAngle)) * sin(-RollAngle)), 2) + pow((((TargetDistance * 
sin((TargetElevation + rate(TargetElevation) * (TargetDistance / 
GUN_SPEED)))) * cos(-PitchAngle) + (TargetDistance * cos((TargetElevation + 
rate(TargetElevation) * (TargetDistance / GUN_SPEED))) * 
cos((repeat((TargetHeading - Heading) + rate(TargetHeading) * 
(TargetDistance / GUN_SPEED)  + 180, 360) - 180))) * sin(-PitchAngle)) * 
cos(-RollAngle) + (TargetDistance * cos((TargetElevation + 
rate(TargetElevation) * (TargetDistance / GUN_SPEED))) * 
sin((repeat((TargetHeading - Heading) + rate(TargetHeading) * 
(TargetDistance / GUN_SPEED)  + 180, 360) - 180))) * sin(-RollAngle)), 2) + 
pow(((TargetDistance * cos((TargetElevation + rate(TargetElevation) * 
(TargetDistance / GUN_SPEED))) * cos((repeat((TargetHeading - Heading) + 
rate(TargetHeading) * (TargetDistance / GUN_SPEED)  + 180, 360) - 180))) * 
cos(-PitchAngle) - (TargetDistance * sin((TargetElevation + 
rate(TargetElevation) * (TargetDistance / GUN_SPEED)))) * sin(-PitchAngle)), 
2))) / 180

How

These FTs convert the target data you're given into positional data, rotates the X, Y, and Z coordinatess according to your Pitch and Roll angles (Yaw is compensated for by the heading FT i used) and converts them back into data your rotators can use.

Of course I didn't write it all like this, I wrote it with multiple setters then wrote a script to compile it into two FTs