OK So as I was typing a post to ask for help on how to code this, I had my EUREKA! moment and managed to figure it out just as I was about to hit Submit.. :D But that left me wonder, given the troubles I have wrapping my head around math and coding, if perhaps there was a more elegant or simpler (cleaner) way to have done this?
What I'm tackling is Rolling induced by Yaw (Rudder), to counter-act the roll by applying a tiny bit of Aileron input only during Yaw events; otherwise, it passes along the Roll input.
(This counter-roll gets applied to the opposite wing to the side I'm "turning" towards, which is why it's a negative-value being multiplied against.)
LEFT WING: Roll>0 | Roll<0 ? Roll : (Yaw>0 ? Yaw * -0.055 : 0)
RIGHT WING: Roll>0 | Roll<0 ? Roll : (Yaw<0 ? Yaw * -0.055 : 0)
(I had tried to use clamp, but ... we won't even get into the mmmmassive failure that resulted in! lol)
TL;DR - There any way to simplify that code? It works as needed, but even to me it just looks ham-fisted... :}
L:
Roll - (Roll=0 ? clamp01(Yaw)*0.055 : 0)
R:
Roll + (Roll=0 ? clamp01(-Yaw)*0.055 : 0)
Yep, that did it! Does exactly the same thing as mine now but shorter!
Thanks :D
(Although, as to why adding the outer parenthesis solved that issue, is definitely beyond me! lmao)
.
I've pinned the functional code and am leaving this line of text to hopefully avoid confusion, should anyone read the comments :P
forgot the parentheses lol
@edensk
Now it ends up canceling out Roll from working, period lol
... And also makes the Aileron move in the opposite direction :}
.
Though, I can't even figure out how that manages to even react with Yaw with that code, given from what I can tell the "IF" part is looking solely for Roll related Input, and the "THEN" is the performing of Yaw-based stuff. EDIT: Nevermind, makes sense now. "IF there is no Roll input" "Then, do this if Yaw is present"
EDIT 2: The Aileron being just a lack of Negative in front of the decimal value.
.
The "ELSE" being zero explains the lack of any Roll input getting applied, and I presume that it should be
: Roll
instead of: 0
?EDIT 3: Nope, I'm a derp! That wouldn't work since the "IF" part means it never will make to the "ELSE" part lol
@Formula350 Oh I see, edited it so it works like yours
@rexzion lol Yea me too :sob: I know enough to kludge together code and get it working (usually...), but I don't actually know the more-advanced stuff that would let me properly get it done.
@edensk Yep I never would've came up with that result.
However, while using yours DOES yield functional results, it actually doesn't produce identical results as mine. (as determined through using DebugExpressions)
.
Situation A:
Situation B:
I only mention that because I was intending to also apply this to the Tail Elevators and they would require significantly more compensation applied than just 0.055, to adjust for the amount of Nose-Down that occurs. Which would actually lead to a situation where if I were applying Yaw+Pitch, my Elevator's input would either be far less-than its max, or far over its max. (depending on whether I'm pitching up or down)
.
It's the latter situation that would be of concern, since it could result in those Elevator flaps stalling-out.
BUT! All examples of functional code like you provided is actually really helpful for me, since I learn better through examples than I do being giving explanations for how to use stuff and trying to get it working. :D
honestly when i make ft code i just add stuff til it works somewhat as intended and i don't touch it again in fear of breaking everything