Profile image

Funky Trees!

Dev WNP78  3.2 years ago

Andrew decided to call the new inputs system I cooked up "funky trees". Somehow escapes me why, but I'll roll with it. Here I'll describe what you can do in the land of funk.

Essentially what this means is that you can enter any mathematical expression (following this syntax) into an input field and it will be evaluated every frame. You can pull in data from a variety of sources, and process these how you like.


What you can now do is use the normal input axes:

  • Pitch
  • Roll
  • Yaw
  • Throttle
  • Brake
  • Trim
  • VTOL
  • LandingGear
  • FireGuns
  • FireWeapons
  • LaunchCountermeasures
  • Activate1
  • Activate2
  • Activate3
  • Activate4
  • Activate5
  • Activate6
  • Activate7
  • Activate8

Flight data

In addition to this you can access some information from the aircraft:

  • Altitude - Aircraft's altitude in metres
  • AltitudeAgl - Aircraft's altitude above ground level in metres
  • GS - The speed relative to the ground (m/s)
  • IAS - The speed relative to the air, adjusted for the desnity of the air (m/s)
  • TAS - The speed relative to the air (m/s)
  • Fuel - The amount of fuel remaining as a proportion of capacity (0 to 1)
  • AngleOfAttack - The angle of attack (angle airflow vertically meets the boresight) in degrees
  • AngleOfSlip - The horizontal equivalent of angle of attack (degrees)
  • PitchAngle - The pitch of the aircraft (degrees)
  • RollAngle - The roll of the aircraft (degrees)
  • Heading - The heading of the aircraft (degrees)
  • Time - The time since the level loaded (seconds)
  • GForce - The acceleration and gravitational "force" acting on the cockpit in G. I know it's not a force. Shut up.
  • VerticalG - The signed vertical component of the "G Force".
  • SelectedWeaponName - The name of the selected weapon
  • Latitude - The North/South position of the craft (metres)
  • Longitude - The East/West position of the craft (metres)
  • PitchRate - The pitch angular velocity in degrees/second
  • YawRate - The yaw angular velocity in degrees/second
  • RollRate - The roll angular velocity in degrees/second (these 3 inputs are better than using rate(PitchAngle) etc, because they account for wrapping around the angle, as well as being in local space: rate(Heading) is different to YawRate)
  • TargetSelected - true if a target is selected, else false.
  • TargetHeading - the heading to the selected target in degrees.
  • TargetElevation - the vertical angle to the selected target in degrees.
  • TargetDistance - the distance to the selected target in metres.


Values that are always the same:

  • pi the mathematical constant pi (half a tau, if you will).
  • e the mathematical constant e.
  • true a true boolean value
  • false a false boolean value


These are useful for... maths or something.

  • Mathematical:

    • +, - addition and subtraction (- can be used as a unary operator, for instance -Pitch

    • *, / multiplication and division

  • Comparison:

    • <, > less than, greater than

    • <=, >= less than or equal to, greater than or equal to

    • ==, != equal to, not equal to

  • Boolean:

    • &, AND

    • |, OR

    • !, NOT (this is a unary operator)

    • Ternary operator: condition ? value_if_true : value_if_false - this chooses between two values based on the condition.


Finally, there's some helpful functions to do maths for you!

  • abs(x) - The absolute (positive) value of x.
  • ammo(name) - The amount of ammo of the weapon with name. Remember to put the name in " quotes.
  • ceil(x) - x rounded up to an integer.
  • clamp(x, min, max) - x clamped between min and max.
  • clamp01(x) - Equivalent to clamp(x, 0, 1).
  • deltaangle(a, b) - The shortest angle delta between angles a and b in degrees.
  • exp(x) - Returns e raised to the power of x.
  • floor(x) - x rounded down to an integer.
  • inverselerp(a, b, x) - Calculates the linear parameter t that produces the interpolant value within the range [a, b].
  • lerp(a, b, t) - Linearly interpolates between a and b, by a proportion of t.
  • lerpangle(a, b, t) - Similar to lerp, but interpolates correctly when values pass 360 degrees.
  • lerpunclamped(a, b, t) - Similar to lerp, but doesn't clamp the value between a and b.
  • log(x, p) - The logarithm of x in base p.
  • log10(x) - Equivalent to log(x, 10).
  • pingpong(x, l) - "Ping-pongs" the value x so it is never larger than l and never less than 0.
  • max(a, b) - The largest value between a and b.
  • min(a, b) - The smallest value between a and b.
  • pow(x, p) - x raised to the power of p.
  • repeat(x, l) - Loops the value x so it is never larger than l and never less than 0.
  • round(x) - Rounds x to the nearest integer.
  • sign(x) - The sign of x (1 if x positive, -1 if x negative)
  • smoothstep(a, b, t) - Similar to lerp, but with smoothing at the ends.
  • sqrt(x) - The square root of x.
  • sin(x) - The sine of x (degrees)
  • cos(x) - The cosine of x (degrees)
  • tan(x) - The tangent of x (degrees)
  • asin(x) - The arc-sine of x (degrees)
  • acos(x) - The arc-cosine of x (degrees)
  • atan(x) - The arc-tangent of x (degrees)

Memory Functions

These are functions that are special because their output not only depends on inputs but their previous state.
- sum(x) - Returns the sum of all it's inputs over time (the integral of x)
- rate(x) - Returns the rate of change of x relative to its value last frame (the derivative of x)
- smooth(x, t) - When loaded, it's output is set to x. As x changes, the output tries to move to x, but at a rate of no greater than t. This is vaguely equivalent to changing the speed of a rotator.
- PID(target, current, p, i , d) - Evaluates a PID controller with the setpoint of "target", process variable "current" and the gains p, i, and d. Equivalent to: p * (target - current) + i * sum(target - current) - d * rate(current)

With all of these at your disposal, I'm excited to see what kind of contraptions you guys come up with, and I'm also open to some suggestions as to some things that could be added.

-WNP78, your funk master.

  • Log in to leave a comment
  • Profile image

    @GKYGG of course you can!!
    pls note i missed one closing parenthesis in my comment

    3 days ago
  • Profile image
    6,885 GKYGG

    @GorillaGuerrilla Can I use it?

    3 days ago
  • Profile image

    Can AltitudeAgl input be put into a secondary cockpit, pitch input? And if so how? (need info on it for a project)

    4 days ago
  • Profile image

    @Khanhlam It was an aerobatic aircraft that I was working on.

    4 days ago
  • Profile image
    1,703 Khanhlam

    @F14FANATIC Is that an F-14? Yeah flat spin is normal in that plane.

    4 days ago
  • Profile image
    Dev WNP78

    @temporaryplanetester FT is only an expressions language, and if/else blocks typically group statements (instructions). What you can do if you want is to use the Activator field on a variable setter (click the downwards arrow to expand it) to only set a variable when a condition is met, and then have another setter for the same variable with the opposite condition. Or, if you want to format your code nicer, you could edit it in an external editor and split your ternary operators across multiple lines, like

        ? value_if_true
        : value_if_false
    +2 6 days ago
  • Profile image

    Idea: Add an if else statement.

    The ternary operator is cool and all, but it can make your code hard to understand if you chain a bunch of them together, so a multi-line if else would be nice to have.

    6 days ago
  • Profile image

    @GorillaGuerrilla Thanks, man. THe roll reversal is more manageable now with the fixed thrust vectoring but it's still there. I'm about to go put this into my aircraft right now. Thanks again.

    12 days ago
  • Profile image

    @LoneSpaceGaming heres the code for the hinge on my ailerons.
    RollInput/1.25 * sign(90 - abs(AngleOfSlip)) - smooth(clamp(clamp01(AltitudeAgl > 2.85)*
    (RYawOut*AngleOfSlip*2.2), -0.23,0.23),0.11)

    note i actually made the roll reversal when the plane is flying backwards at angleofslip > 90. so lets say if u want the roll to behave the opposite when aoa is above 45 u might want to change that part right after rollinput to * sign(45 - abs(AngleOfAttack)

    it doesnt matter how u messed up ur design, this will eventually help u one day if u are making psm planes

    12 days ago
  • Profile image

    I'm stupid, my thrust vectoring was going opposite to my afterburner, so even with afterburners on it did roll very well in PSM. So I guess when I hit around 15 degrees of AoA the thrust vectoring of the normal engine was enough to roll the aircraft in the opposite direction.

    13 days ago
  • Profile image

    Anyone know how to invert the ailerons when above a certain AOA? My plane 5/6th gen fighter has roll reversals and I want to get rid of it, it just doesn't fit with a 5/6th gen aircraft.

    13 days ago
  • Profile image

    @Misterrobertinho from my understanding, yes it is :)

    15 days ago
  • Profile image

    @CaptEarle591 I just saw this and I've been Wondering how to do that thank you Sincerely - F14FANATIC

    +2 24 days ago
  • Profile image

    I made a plane that can identify if it's in a flat spin or not and which direction the flat spin is. I will eventually post that plane but in the mean time it's still in the making.
    But if anybody Has any questions or wants to do this for themselves contact me at my discord (read my bio)

    +1 24 days ago
  • Profile image
    1,148 mitsuki

    @CaptEarle591 Thanks, I'll test this on my build asap

    +1 27 days ago
  • Profile image

    @mitsuki smooth(Throttle, X)
    Replace the X with a number
    The smaller the slower the start
    smooth(Throttle, 0.05)
    This is what I use

    +2 27 days ago
  • Profile image
    1,148 mitsuki

    anyone know how to delay a engine startup? I want my VTOL nozzles slowly start up instead of going from 0-100 whenever I activate my afterburners

    +1 one month ago
  • Profile image

    @Havonec ooooooohhh I thought you needed some complicated XML for it

    one month ago
  • Profile image
    1,079 Havonec

    @CatMasterLuke but for the cannon

    one month ago
  • Profile image
    1,079 Havonec

    @CatMasterLuke like where you press to edit fuselages

    one month ago
  • Profile image
    1,079 Havonec

    @CatMasterLuke btw you8 can make it mutirole in the non-mod settings

    one month ago
  • Profile image

    @GorillaGuerrilla I need context

    one month ago
  • Profile image
    1,079 Havonec


    one month ago
  • Profile image
    1,079 Havonec

    @GorillaGuerrilla when i out in the code nothing is happening

    one month ago
  • Profile image

    @Havonec i actually stumbled upon this to learn how to do it.
    u can change the code so that its time sensitive to blink.
    my rate of climb reading is rate based. just change it to sin(Time * Anynumber) > 0

    one month ago
  • Log in to see more comments