Profile image

FT turret stabilized code

11.0k SenSkysh  11 days ago

For cannons

Elevation

clamp((acos((cos(RollAngle) * (-sin(-PitchAngle)) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin(((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity) + (asin((cos(TargetElevation + (rate(TargetElevation)) * TargetDistance/Velocity) * (TargetDistance + rate(TargetDistance)*TargetDistance/Velocity) * 9.81)/(Velocity * Velocity))/2))) * cos((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + sin(RollAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin(((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity) + (asin((cos(TargetElevation + (rate(TargetElevation)) * TargetDistance/Velocity) * (TargetDistance + rate(TargetDistance)*TargetDistance/Velocity) * 9.81)/(Velocity * Velocity))/2))) * sin((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + cos(RollAngle) * cos(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * cos(((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity) + (asin((cos(TargetElevation + (rate(TargetElevation)) * TargetDistance/Velocity) * (TargetDistance + rate(TargetDistance)*TargetDistance/Velocity) * 9.81)/(Velocity * Velocity))/2))))) / (TargetDistance + rate(TargetDistance) * TargetDistance/Velocity)) - 90),negativeAngle,positiveAngle)

Heading

clamp(deltaangle(turretAngle,
atan((sin(RollAngle) * sin(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin(((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity) + (asin((cos(TargetElevation + (rate(TargetElevation)) * TargetDistance/Velocity) * (TargetDistance + rate(TargetDistance)*TargetDistance/Velocity) * 9.81)/(Velocity * Velocity))/2))) * cos((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + cos(RollAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin(((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity) + (asin((cos(TargetElevation + (rate(TargetElevation)) * TargetDistance/Velocity) * (TargetDistance + rate(TargetDistance)*TargetDistance/Velocity) * 9.81)/(Velocity * Velocity))/2))) * sin((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + cos(-PitchAngle) * (-sin(RollAngle)) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * cos(((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity) + (asin((cos(TargetElevation + (rate(TargetElevation)) * TargetDistance/Velocity) * (TargetDistance + rate(TargetDistance)*TargetDistance/Velocity) * 9.81)/(Velocity * Velocity))/2))))) / (cos(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin(((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity) + (asin((cos(TargetElevation + (rate(TargetElevation)) * TargetDistance/Velocity) * (TargetDistance + rate(TargetDistance)*TargetDistance/Velocity) * 9.81)/(Velocity * Velocity))/2))) * cos((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + sin(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * cos(((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity) + (asin((cos(TargetElevation + (rate(TargetElevation)) * TargetDistance/Velocity) * (TargetDistance + rate(TargetDistance)*TargetDistance/Velocity) * 9.81)/(Velocity * Velocity))/2)))))) + (((cos(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin(((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity) + (asin((cos(TargetElevation + (rate(TargetElevation)) * TargetDistance/Velocity) * (TargetDistance + rate(TargetDistance)*TargetDistance/Velocity) * 9.81)/(Velocity * Velocity))/2))) * cos((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + sin(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * cos(((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity) + (asin((cos(TargetElevation + (rate(TargetElevation)) * TargetDistance/Velocity) * (TargetDistance + rate(TargetDistance)*TargetDistance/Velocity) * 9.81)/(Velocity * Velocity))/2))))) < 0) ? (((sin(RollAngle) * sin(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin(((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity) + (asin((cos(TargetElevation + (rate(TargetElevation)) * TargetDistance/Velocity) * (TargetDistance + rate(TargetDistance)*TargetDistance/Velocity) * 9.81)/(Velocity * Velocity))/2))) * cos((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + cos(RollAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin(((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity) + (asin((cos(TargetElevation + (rate(TargetElevation)) * TargetDistance/Velocity) * (TargetDistance + rate(TargetDistance)*TargetDistance/Velocity) * 9.81)/(Velocity * Velocity))/2))) * sin((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + cos(-PitchAngle) * (-sin(RollAngle)) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * cos(((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity) + (asin((cos(TargetElevation + (rate(TargetElevation)) * TargetDistance/Velocity) * (TargetDistance + rate(TargetDistance)*TargetDistance/Velocity) * 9.81)/(Velocity * Velocity))/2)))))>0) ? 180 : -180) : 0)),negativeAngle,positiveAngle)

For guns

Elevation

clamp((acos((cos(RollAngle) * (-sin(-PitchAngle)) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity)) * cos((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + sin(RollAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity)) * sin((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + cos(RollAngle) * cos(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * cos((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity)))) / (TargetDistance + rate(TargetDistance) * TargetDistance/Velocity)) - 90),negativeAngle, positiveAngle)

Heading

clamp(deltaangle(turretAngle,
atan((sin(RollAngle) * sin(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity)) * cos((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + cos(RollAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity)) * sin((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + cos(-PitchAngle) * (-sin(RollAngle)) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * cos((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity)))) / (cos(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity)) * cos((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + sin(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * cos((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity))))) + (((cos(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity)) * cos((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + sin(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * cos((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity)))) < 0) ? (((sin(RollAngle) * sin(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity)) * cos((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + cos(RollAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity)) * sin((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + cos(-PitchAngle) * (-sin(RollAngle)) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * cos((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity))))>0) ? 180 : -180) : 0)),negativeAngle, positiveAngle)

example of a car with two turrets

Source

Elevation

clamp((acos((cos(RollAngle) * (-sin(-PitchAngle)) * (R * sin(O) * cos(F)) + sin(RollAngle) * (R * sin(O) * sin(F)) + cos(RollAngle) * cos(-PitchAngle) * (R * cos(O))) / R) - 90),negativeAngle,positiveAngle)

Heading

clamp(deltaangle(turretAngle,
atan((sin(RollAngle) * sin(-PitchAngle) * (R * sin(O) * cos(F)) + cos(RollAngle) * (R * sin(O) * sin(F)) + cos(-PitchAngle) * (-sin(RollAngle)) * (R * cos(O))) / (cos(-PitchAngle) * (R * sin(O) * cos(F)) + sin(-PitchAngle) * (R * cos(O)))) + (((cos(-PitchAngle) * (R * sin(O) * cos(F)) + sin(-PitchAngle) * (R * cos(O))) < 0) ? (((sin(RollAngle) * sin(-PitchAngle) * (R * sin(O) * cos(F)) + cos(RollAngle) * (R * sin(O) * sin(F)) + cos(-PitchAngle) * (-sin(RollAngle)) * (R * cos(O)))>0) ? 180 : -180) : 0)),negativeAngle,positiveAngle)

How it works?

It's hard to explain ... In short, a spherical coordinate system is converted to a cartesian one, multiplied by the rotation matrix and returned back
Before transfer to FT, it looked something like this

  • Log in to leave a comment
  • Profile image
    11.0k SenSkysh

    @tomlin5412 And the example works. Have you entered all the variables?

    8 days ago
  • Profile image

    heading for guns doesn't work

    8 days ago
  • Profile image

    @EternalDarkness can you add this to the pinned forum of useful links?

    9 days ago
  • Profile image
    11.0k SenSkysh

    ?@NightmareCorporation

    10 days ago
  • Profile image

    What....?

    10 days ago
  • Profile image
    11.0k SenSkysh

    @SnoWFLakE0s Changed, but I don't see any changes

    10 days ago
  • Profile image
    17.5k UltraLight

    super cool dude

    11 days ago
  • Profile image
    39.0k SnoWFLakE0s

    Use code boxes.
    long code thing, using three ticks instead of 1 on each side

    11 days ago
  • Profile image
    19.0k Nerfaddict

    good god those are long codes

    11 days ago