Profile image

Funky Trees!

Dev WNP78  5.4 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.

Inputs

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.

Constants

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

Operators

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.

Functions

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)
  • atan2(y, x) - The angle in degrees whose tangent is y/x. In other words the angle (argument) of a vector

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
    195 G2027RR

    @LitoMikeM1 I already figure it out thanks

    3 days ago
  • Profile image

    @G2027RR do you want it to not pitch up too drastically at high speeds?

    3 days ago
  • Profile image

    how do I make a button instantly go up after being pressed? or at least make a bool that says true the moment the button is pressed, but stays false even when the finger is still on the button until pressed again?

    6 days ago
  • Profile image
    195 G2027RR

    How do I make the pitch of my aircraft change based on the speed

    It's a fighter jet and the funky code for the mother of the back wings is (Pitch+Yaw-Brake)

    7 days ago
  • Profile image
    2,870 ACEVIPER9710

    @LitoMikeM1 smooth(clamp01(group),x)

    9 days ago
  • Profile image
    3,453 CDTX2011
    19 days ago
  • Profile image
    165 TheTThek

    How to delay piston, like when I activate there's a 2 second delay, when I deactivate there's no delay
    I'm kinda new to this game to be honest.

    20 days ago
  • Profile image

    @CDTX2011 (smooth(LandingGear, 0.875))*-1 or sign(smooth(LandingGear, 0.875))

    +1 20 days ago
  • Profile image

    how do you make a rotator that's constantly rotating when firing weapons, but FREEZES (doesn't reset to zero) when you stop?

    20 days ago
  • Profile image
    2,860 TateNT34

    Part of the code for the guns on the
    B-25J Mitchell: https://www.simpleplanes.com/a/hoGyGV/B-25J-Mitchell
    I’m trying to add the bombarder’s nose gun to the B-57B canberra: https://www.simpleplanes.com/a/9N4V17/B-57B-Canberra

    Distance/800) * sin((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/800)) * cos((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/800))) + sin(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/800) * cos((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/800)))) < 0) ? (((sin(RollAngle) * sin(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/800) * sin((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/800)) * cos((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/800))) + cos(RollAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/800) * sin((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/800)) * sin((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/800))) + cos(-PitchAngle) * (-sin(RollAngle)) * ((TargetDistance + rate(TargetDistance) * TargetDistance/800) * cos((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/800))))>0) ? 180 : -180) : 0

    23 days ago
  • Profile image

    @TateNT34 probably some parentheses out of place, if you can send the code, I can help

    23 days ago
  • Profile image
    2,860 TateNT34

    @VargasSoldierT What does “ Variable error: Stack empty “ mean?

    23 days ago
  • Profile image

    @LitoMikeM1 yes, using a variable for example, name Increment = Activate4?clamp(smooth(increment+0.01,0.01),0,1):
    clamp(smooth(increment-0.01, 0.01),0,1) smooth, keeps the increment rate at 0.01, and clamp, to keep it between 0 and 1

    24 days ago
  • Profile image
    3,453 CDTX2011

    so uh how do you invert "smooth(LandingGear, 0.875)" cause i'm trying to use reszied airbrakes as landing gear doors(inverting normally make it deploy while the gear retracts and i want to make it so they both deploy at the same time)

    25 days ago
  • Profile image

    is there a way to make a thingy go from 0 to 1 when an AG is activated (or from 1 to 0 when deactivated) in a linear curve instead of instantly going?

    one month ago
  • Profile image

    @TheVizzyLucky ngl i didn't read your name and I was thinking “at this point, just get juno” lol

    one month ago
  • Profile image

    @sennpai114 they tell you the distance between the target you are tracking what direction they are going in and how high they are.

    one month ago
  • Profile image

    Does anyone know what do rate(TargetDistance),rate(TargetHeading) and rate(TargetElevation) actually mean? I only know they output signed numbers

    +1 one month ago
  • Profile image
    2,347 Stephen22

    I'm trying to do a thing for radar try GPT isn't really helping me that much track DPT gave me this as a funky tree round(smooth(rand(100, 300), 0.5)) + " MPH" I'm trying to make my label go a random calculator speed between 100 mph to 300 mph randomly

    +1 one month ago
  • Profile image

    @griges How can I do that? I can only cycle between Roll, Pitch and Yaw.
    Edit: Made it work using XML editing now, Thanks!

    +1 one month ago
  • Profile image
    2,752 griges

    @TheVizzyLucky just use +
    put the Roll+calculatedValue in each wing's control surface

    one month ago
  • Profile image
    2,752 griges

    @HordTechnicians idk how to activate camera
    i dont think theres a way

    one month ago
  • Profile image

    How exactly can I use this to control aircrafts? I'm trying to automatically control the Roll with a dynamically calculated value. These calculations work fine, but I can't get them to do anything. So, if the value is calculatedValue and the Input I want to control is Roll, what do I have to use as Variable Name and what is the Expression (my first thought, Name = Roll and Expression = calculatedValue, didn't work)? This is probably a dumb question, but I'm coming from JNO where the programming system is... different.

    one month ago
  • Profile image

    @griges I’ve been testing with trying to add input and playing with the variables but nothing worked

    +1 one month ago
  • Profile image
    2,752 griges

    @LitoMikeM1 i tried using smooth(Activate1,0.1)
    but it delays only whaen turning off ag, not turning on

    +1 one month ago
  • Log in to see more comments