• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

FSXA Newbie request help understanding a code

Messages
64
Country
unitedstates
Hello everyone!
So, I'm slowly trying to understand how to code. Reading through the SDK, seeing everyone's examples... alot of great gouge but I'm a little slow on the power curve.
I'm trying to create a simple wing flex animation based on G Forces and velocity. I know there's a code within this forum that is rather long, but I'm trying to build one from scratch so I can better understand what each section of the code means, and how the math is applied to it. But, of course, my efforts generally fail because I'm clueless.
So, what I'm trying to do is have the wings flex between 2.5 and 4 g's above 215 knots. The animation for the flexing is 400 keyframes. Below is the code so far:

Code:
<PartInfo>
<Name>wing_flexing</Name>
<AnimLength>400</AnimLength>
       <Animation>
             <Parameter>
                    <Code>
                    (A:VELOCITY BODY Z, knots) 215 &gt; if{
                    (A:G FORCE,gforce) 2.5 min 4 max 1 * } els{ 0 }
                    </Code>
                    <Lag>400</Lag>
             </Parameter>
</Animation>
</PartInfo>


So, of course this doesn't work... I don't quite understand what the min max does.. the multiplier at the end I believe is supposed to be used to equal out the equation to "400", and perhaps I need to subtract something from the 2.5 to make it equal out to zero... I just don't know what I'm doing.

If anyone would be so kind as to help me with this code and give as detailed or brief a description of what each section means, I'd greatly appreciate it, and I it will make alot of the other codes on the site make much more sense to me!

Thank you for any assistance anyone can provide!

Jamal
 
Code:
<PartInfo>
<Name>wing_flexing</Name>
<AnimLength>400</AnimLength>
       <Animation>
             <Parameter>
                    <Code>
                    (A:[COLOR="SeaGreen"]AIRSPEED TRUE[/COLOR], knots) 215 &gt; 
                   if{ (A:G FORCE,gforce) [COLOR="Red"]100 *[/COLOR] } 
                   </Code>
                    <Lag>400</Lag>
             </Parameter>
</Animation>
</PartInfo>

100 *
4 gforce * 100 = 400 Key Frames

Animation

m41yxo6qdvlz.jpg



els{ 0 } is not necessary ( the animation works parrallel to the gforce value )
<Lag>400</Lag> eventually reduced to 150!
 
Here's my guess:

Code:
<PartInfo>
<Name>wing_flexing</Name>
<AnimLength>400</AnimLength>
       <Animation>
             <Parameter>
                    <Code>
                    (A:VELOCITY BODY Z, knots) 215 &gt; (A:G FORCE,gforce)  2.5 &gt; &amp;&amp; if{ (A:G FORCE,gforce) 4 min 2.5 max 2.5 - 266 *  } 
                    </Code>
                    <Lag>150</Lag>
             </Parameter>
</Animation>
</PartInfo>

This means:

1. If > 215 knots and (&amp;&amp; ) G Force > 2.5 then
2. Start with G Force (4 maximum and 2.5 minimum) These are backwards from what you may think - that's just the way they work... These are not really needed, since the code doesn't run below 2.5 (due to the if statement) and over 4 you are just maxed out on keyframes anyway.
3. Modify this G-force by:
...a. Subtracting 2.5 from it. This takes 2.5 to 4 and converts it to 0 to 1.5.
...b. Multiplying by 266. This converts 0 to 1.5 to 0 to 399 (your keyframes).

The lag must be determined by trial and error. Use whatever value smooths the motion as the G-force increases. Check this in turbulence, etc.

Note that there may be a sudden flexing when the plane exceeds 215 knots - you may also want to include a speed determination inside the if{ statement as well (i.e. at 215 kts it = 0% G-force effect and at some higher speed it = 100%). This will then allow smooth changes with both speed and G force.

Assuming the speed effect maxes out at 400 knots, then it would look something like:

Code:
<PartInfo>
<Name>wing_flexing</Name>
<AnimLength>400</AnimLength>
       <Animation>
             <Parameter>
                    <Code>
                    (A:VELOCITY BODY Z, knots) 215 &gt; (A:G FORCE,gforce)  2.5 &gt; &amp;&amp; if{ (A:G FORCE,gforce) 2.5 - 266 *  (A:VELOCITY BODY Z, knots) 215 - 0.0054 *  * } 
                    </Code>
                    <Lag>150</Lag>
             </Parameter>
</Animation>
</PartInfo>

Airspeed is from 215 to 400 knots. Subtract 215 and then it is between 0 and 185. Multiply by 0.0054 and it's between 0 and 1. Multiply this with the G-force keyframe value for a final result.

Hope this helps,
 
Thank you so much, guys! Seeing the different methods really helps!

Tgibson, the animation is only supposed to occur over 215 knots, with no airspeed limit, but the code and explanation you gave me for the speed range really helps me understand all this more!

I'm going to try this out tonight, and let you all know how it works!

Again, thank you so much!

Jamal
 
You're welcome. :)

My last code means that the effect starts working at 215 knots (barely), gets progressively more obvious up to 400 knots, and stays at maximum effect at anything over that. Pretty realistic I would think. If you need to change the speeds, that's not hard.

The first code box (no effect at 215 knots, and maximum effect over 215 knots) is not very realistic.
 
ooooh, I'm tracking you now Tgibs!!

I tried out the first one, but it didn't work... I'm going to try the second one tomorrow after work! This is so exciting, I'm actually learning something! :)
 
My code has not been tested, and thus may need some tweaking. Also, it will not work in native FSX models because you need to edit the XML for that sim.
 
I need to copy this into my archives. Thanks Tom for the tutorial.

I never did understand wingflex and G-load equasions.
 
My code has not been tested, and thus may need some tweaking. Also, it will not work in native FSX models because you need to edit the XML for that sim.

Heya Tom,
This is for a a ground up project I'm working on of a sci fi fighter. It has very thin wings, similiar to the F-14, and I'd figure I'd put a bit of flexing in there.

Jamal
 
w00t, wing flexing looks fantastic!! Thanks again Tgibs! All I have to do now is mess around with the lag. But that second code did the trick!

Now, at the end of the code, is it necessary to have two multipliers there? * *

Jamal
 
Hi,

Glad to help.

Yes, the second * is necessary - think of it this way:

(G-Force code): (A:G FORCE,gforce) 2.5 - 266 *

(Speed code ): (A:VELOCITY BODY Z, knots) 215 - 0.0054 *

Now multiply them together: *

Hope this helps,
 
Back
Top