Profile image

Funky Trees!

Dev WNP78  5.5 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
    127 Peterwrpl

    Im back, now i need help with something else, can you enter "autopilot" (altitude hold) with a button instead of needing to pause the game?

    +1 8 days ago
  • Profile image

    Hello,does anyone know what is the attitude of my target?

    9 days ago
  • Profile image

    Can someone create a line of code for me?
    Like im still stuck on the plane engine, reverse thing fixed but now i wanna add jet engine blur, like yk when the jet engines fan starts to speed up theres this cool blur when your taking off and also a lil when in the air
    Like i wanna make a custom throttle for it, still controlled through the main controls
    For example i put the throttle up to 100, the blur starts
    But when i turn on the killswitch it stops, but the throt is still at 100 so that means if i turn it on again with the throt at 100 the jet engine's fan wont be moving at realistic speeds to create the blur
    So i need another variable that acts like the throttle so when i turn the throt up, it goes at the same pace as the throttles acceleration when you turn it up but when you turn the killswitch/fuelfeed off it resets to 0 throttle and when you turn it on, still showing 100 throttle on the panel the variable pulls the 100 throt back up at the same pace as when you pull the throt up
    Sorry if its confusing cuz idk how to explain things well

    12 days ago
  • Profile image
    127 Peterwrpl

    @Polarity nvm im blind lol

    12 days ago
  • Profile image
    127 Peterwrpl

    @Polarity its a beacon light but i think it only has an activation group

    12 days ago
  • Profile image
    1,017 Polarity

    @Peterwrpl could it be because IAS is measured in meters per second and not mph or km/h? Also, what type of light is it? the beacon and formation lights both have input fields on the XML editor.

    13 days ago
  • Profile image
    127 Peterwrpl

    @Polarity wait nvm it isnt working probably because the light doesnt have an input, only an activation group

    13 days ago
  • Profile image
    127 Peterwrpl

    @Polarity thank you, i needed it for a warning light in the cockpit

    13 days ago
  • Profile image
    1,017 Polarity

    @Peterwrpl "true" isn't used for the landing gear states, use something like this
    LandingGear=0&IAS>=300
    Also, if you're doing it on a rotator or hinge don't put it in the activation group, put it as input.

    16 days ago
  • Profile image
    127 Peterwrpl

    Can anyone explain why this isnt working as an activation group?
    LandingGear==true&IAS>=300

    +1 17 days ago
  • Profile image

    @GonzaJP oh thx dude!!

    18 days ago
  • Profile image

    @Sumrandomdud Try with abs(VTOL) to always have a positive number even with a negative VTOL value.

    You can use clamp(x, min, max) to limit output value between min and max of your choice, or 0 and 1 using clamp01(x) in case you need it too

    19 days ago
  • Profile image

    guys how do i make it so that the throttle never goes above 1? (100%)
    Like im making a reverse thruster for my plane and i wanna make it so that when i deploy it the main thrust drops if active, heres the code its super simple

    Throttle - VTOL*0.75
    Problem is if i put the VTOL value below 0 itll get the throttle to 1.75 (175%)
    Anyone knows how 2 fix it?

    +1 21 days ago
  • Profile image

    Does anyone know the specifics on selectedWeaponName, like say if I need a bomb Bay to open when I select a bomb?

    23 days ago
  • Profile image

    @LitoMikeM1 use smooth(x, (how fast it curves up, I usually use 0.1-1))

    +2 one month ago
  • Profile image

    @ChaseplaneKLWith1MG Idk how to funky but what ive been doing is just looking for builds with landing gear doors that actually open, especially ones with delay and kinda reverse engineer the code.

    +1 one month ago
  • Profile image

    Does anyone know how to make a hinge open immediately but close after a delay? (Need to know for Landing Gear doors)

    +2 one month ago
  • Profile image

    @LitoMikeM1 or if a button can launch countermeasures and change a variable at the same time then maybe ja

    2 months ago
  • Profile image

    @vSoldierT sorta like how if a button is set up to do countermeasures it only does countermeasures once per like second unless if you spam the button

    2 months ago
  • Profile image
    1,777 vSoldierT

    @Flyinguy It doesn't seem to work, well you just need to put in the hook input, (AltitudeAgl < 60?1 * clamp01(GearDown):0)

    the multiplication is a check if GearDown is true or false, that is, if GearDown is 0, it will be 10=0, if GearDown is true, 11=1. And remember to use AltitudeAgl, which is more precise (I tested it on your f-26 and it worked).

    2 months ago
  • Profile image
    195 Flyinguy

    @vSoldierT It’s OK. I tried LandingGear & Altitude<60 & Activate8. But it was actually GearDown or something similar. But I dont think the * would work, isn’t that multiply? Anyways if you want to see the tail hook it is F-26 better.

    +1 2 months ago
  • Profile image
    4,553 TateNT34

    @VargasSoldierT Thx, it still doesn’t work tho. I’ll make a post about it later with the plane. :)

    2 months ago
  • Profile image
    1,777 vSoldierT

    @LitoMikeM1 I didn't understand very well, if you can explain better I can help

    2 months ago
  • Profile image
    1,777 vSoldierT

    @Flyinguy AltitudeAgl<60?1*clamp01(GearDown):0

    2 months ago
  • Profile image
    195 Flyinguy

    I need help with an auto tail hook, I need it to deploy below 60 meters AND when the gear is deployed

    +1 2 months ago
  • Log in to see more comments