Profile image

Funky Trees!

Dev WNP78  1.3 years ago

This post has information useful for those using the 1.9 beta.
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.


First, you can do everything you used to be able to. The new system will only be activated if the input doesn't fit the old system, so all old builds should remain functional.

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 &quot; 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

    Thank you very much

    5 days ago
  • Profile image

    hey, i need some code that tells a rotator where a target is relative to the aircraft. for an example on a radar, a rotator would point towards where the target is.

    26 days ago
  • Profile image

    Noice

    one month ago
  • Profile image
    1,474 L0RR3B0RR3

    So, recently I just caught word of Funky Trees, I'm having a hard time learning how to use it and how to begin writing scripts that I can use on my aircraft. For instance, a lot of aircraft have a special way of retracting their landing gear, in which the tire first gets retracted and then comes the cover. Plz, help?

    +1 one month ago
  • Profile image
    51.8k Beefy

    After I built the Falcon's code i realized there's a better way to write stuff lmao

    one month ago
  • Profile image
    29.5k JoshuaW

    @BurkeAircraft1 smooth((GForce>30),1+clamp01(GForce<=30)*99)=1
    This will trigger when G has been over 30 for 2 seconds

    one month ago
  • Profile image
    29.5k JoshuaW

    @ProjectVideoGame GS * cos(AngleOfSlip) * abs(cos(AngleOfAttack)) should do that

    one month ago
  • Profile image

    @AeroForta I recommend this work powered by @JoshuaW

    +1 one month ago
  • Profile image

    Help, im making auto targeting turret. It uses two rotators, 1 horizontal rotator with uses TargetSelected and TargetHeading(i think) then 1 vertical rotator with uses TargetSelected and Target Elevation. The Problem is i don't know how to apply this in both rotators input, so i really appreciate it if you help me.

    one month ago
  • Profile image

    @WNP78 then I fixed problem like this:The real "Sign(x)" is:
    (sign(x)-clamp01(x=0)) .

    XD

    one month ago
  • Profile image

    @WNP78 I still feel confused about function: sign(x), when the "x" is "zero", the output of sign(x) still is "1", not "0".

    one month ago
  • Profile image

    I need help can someone make funky tree code that makes a detacher detach when a g limit is broken for a couple seconds

    one month ago
  • Profile image
    0 n1kdem

    @OPaiTaOn there you go
    TargetSelected ? TargetDistance / (1250 -
    rate(TargetDistance)) : 60

    one month ago
  • Profile image

    Hi! Faced the problem of high frequency noise in the control system at low speeds (about 0-20 kmh). I should make a low pass filter, but I have no idea how to make it. Or is it possible to solve the problem differently? This noise does not really interfere, but rather just annoys with constant twitching of surfaces. Thank you!

    one month ago
  • Profile image

    @linxiaofeng2339
    not what I am looking for,
    I want it to be specific (negative and positive vectors), but all speed data can't go in the negatives, only calculates the speed, not vector

    (Z+ is forward, Z- is Backward)
    I was planning to use latitude and longitude and heading the get precise Z vectors for all directions

    2 months ago
  • Profile image

    @ProjectVideoGame Input:
    x*(IAS(or TAS or GS)>----?1:0)

    2 months ago
  • Profile image

    @nicolascolissi14 Input:
    (Throttle/0.9)*(Throttle<0.9?1:0)

    2 months ago
  • Profile image

    @Junkers87 No .

    2 months ago
  • Profile image
    1,175 Egorka2001

    @Dimassas9988 так это и есть страница с документацией. если хочешь понять, что написано, то учи английский

    2 months ago
  • Profile image

    Помогите дайте команды синтаксис и слова для программирования деталей моего самолета

    2 months ago
  • Profile image
    2,984 Mikey101234

    I don’t know how to but you can change the lifespan of said projectile, the time is in seconds, the way I find out the “lifetime” (range) of a weapon is by looking up how fast said ammo is, set that to the weapon(don’t forget to convert measurements),divide the answer by the range of the irl weapon, and then divide it by 60(or something like that) to get the realistic range of a weapon, I did it and I got a lifespan of 17.6904755 seconds at a velocity of 840 m/s@OPaiTaOn

    2 months ago
  • Profile image
    5,641 Creativit

    I'm not sure if this is still open to suggestions, but it says so in the post so here goes: what about a "sensor" part that can collect additional flight data similar to a cockpit block, and have an ID of some sort, then a function to retrieve the data, something like: flightdata(x, y) where x is the flight data you want from the sensor with ID of y. This could open up a variety of new things not possible before, and even create the ability to make user-defined variables.

    +3 2 months ago
  • Profile image
    3,540 OPaiTaOn

    how can i make a cannon projectile detonate by proximity? I want to make a flak 88

    +1 3 months ago
  • Profile image
    90 Maroon

    @Urocyon (Time = (Wanted time in seconds)) would probably do it.

    Dunno about the actual time of day though

    +1 3 months ago
  • Profile image
    12.3k Urocyon

    Is there a way to make lights activate due to time of day?

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