• 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 Controlled Animation Question

Paul Domingue

Resource contributor
Messages
1,532
Country
us-california
I have several animated parts on my model that need to be controlled by IAS and some by AOA. I have no idea at this point how to enable this. I assume that I will have to create a new variable in the model definition file. Are there any examples of code available that I could study in relation to what I want to achieve?
 
The following script will animate a needle if the airspeed is over 80 kias, and the aircraft is off the ground.

The scalar will drive the needle from -1.0 to +1.0 over a 120º arc. The bias of +50 is such that frame 0 of the 100 frame animation will be the zero point...

Code:
<Animation name="CJ1_AoA_needle" guid="e5801d07-b465-4cdb-9b28-8327099a193c" length="100" type="Sim" typeParam2="CJ1_AoA_needle" typeParam="AutoPlay" />

  <PartInfo>
    <Name>CJ1_AoA_needle</Name>
    <AnimLength>100</AnimLength>
    <Animation>
      <Parameter>
        <Code>
          (A:Airspeed select indicated or true, knots) 80 &lt; (A:SIM ON GROUND,bool) &amp;&amp;
          if{ 0 }
          els{ (A:INCIDENCE ALPHA, degrees) 0.0857143 * 50 + }
        </Code>
      </Parameter>
      <Lag>10</Lag>
    </Animation>
  </PartInfo>

You will find quite a few examples of XML scripting here: http://www.aerodynamika.com/cgi-bin/yabb2/YaBB.pl?board=XML

Simply put though, the task is to convert "some number" from FS into a format that will fit within the number of keyframes we plan to use in Max/GMax/FSDS. The most fundamental formula we need to remember is this:

SIM: Converts simvar to keyframes: simvar * scale + bias = keyframes

Let's take a look at a simple example that will make use of the entire formula. Our task is to script a vertical speed indicator. Our VSI will indicate -6000 fpm to 6000 fpm, and we are going to use 300 frames for our animation. Why 300 frames instead of 100? Because the fewer frames we use the less accurate our VSI will be!

Now we know that the sim variable will be sent in absolute numbers, so the first thing we want to do is divide by 40, so the result will be -150 to +150 (we could do this any number of different ways, but this is the simplest solution)...

(A:VERTICAL SPEED, ft/min) 40 /
-or to "fit the formula" we could multiply by a scalar to get the same result-
(A:VERTICAL SPEED, ft/min) .025 *

Now because our zero point is at frame 150, we need to add the bias to the calculation...

simvar * scale + bias = keyframes
Code:
(A:VERTICAL SPEED, ft/min) .025 * 150 +

If we now plug in some numbers to validate our formula, the result is this table:

6000 * 0.25 + 150 = 300
0 * 0.25 + 150 = 150
-6000 * 0.25 + 150 = 0
 
Last edited:
Thank you Bill.

You have been a wealth of knowledge for me for several years. This should give me a good start.

Paul
 
No problem, Paul. I'm happy to share what I've learned. I'd even be more than happy to share the skinned knuckles and other assorted pains I've endured during the process of learning! :rotfl:

For what it's worth, the CJ1_AoA_needle script example above I actually used to animate the external "AoA Transducer Vane" on one of my aircraft.
 
I need this type of AoA gauge to activate the suction relief doors and a combination of AoA and IAS depending on the situation to control the (I don't know what their called) intake baffle plates that restrict the amount of air entering at high speeds and or high AoA on my model of the Sukhoi Su-37 demonstrator. I also need to setup slats. I started on the model a very long time ago and then shelved it working on other things then someone in the sim community inspired me to complete it.
 
I have been digging through as much information as I can but still am at a loss as to how to write what I want to happen in the animation. I have tried several changes but can't grasp what I need to write for it to work. In the following <PartInfo> the only line that works is the first one. How do I have it read each step? I suspect that everything could be written into just the first line but again I have no concept as to how this would be done.
Now to make things even more complicated I want each increment of the slat animation to call a FS keyboard key press, the F6 and F7 keys. Since the animation is only visual I need it to call a leading edge flap section of the aircraft.cfg so that the lift and drag scalars come into effect.

Another question is what is the difference between <Code> and <Sim>? I see both being used.

Oh if only I could write this in Pascal life would be so much easier.

Your grateful code idiot
Paul

Code:
<PartInfo>
             <Name>su37_slats</Name>
	<AnimLength>1000</AnimLength>
	<Animation>
		<Parameter>
			<Code>
                    			(A:AIRSPEED INDICATED, knots) 110 &gt; if{ 148 } els{ 0 }
				(A:AIRSPEED INDICATED, knots) 130 &gt; if{ 290 } els{ 148 }
				(A:AIRSPEED INDICATED, knots) 150 &gt; if{ 432 } els{ 290 }
				(A:AIRSPEED INDICATED, knots) 170 &gt; if{ 574 } els{ 432 }
				(A:AIRSPEED INDICATED, knots) 190 &gt; if{ 716 } els{ 574 }
				(A:AIRSPEED INDICATED, knots) 210 &gt; if{ 858 } els{ 716 }
				(A:AIRSPEED INDICATED, knots) 230 &gt; if{ 1000 } els{ 858 }
			</Code>
		</Parameter>
		<Lag>25</Lag>
	</Animation>
</PartInfo>
 
Last edited:
I have this code now that works but my math is so rusty I can't quite get proper scale and bias to even out the animation. IAS range is from 140 to 250 and animation length is 920. It's smooth at the high end but not on the low. IAS 250 * 3.4 + 110 = 920 but IAS 141 * 3.4 +110 = 589.4 so that doesn't work quite right. I need to brush up on my algebra 101. :o

Code:
<PartInfo>
		<Name>su37_slats</Name>
		<AnimLength>920</AnimLength>
		<Animation>
			<Parameter>
				<Code>
                    (A:AIRSPEED INDICATED, knots) 140 &lt; if{ 0 } els{ (A:AIRSPEED INDICATED, knots) 3.4 * 110 + }
				</Code>
			</Parameter>
			<Lag>200</Lag>
		</Animation>
    </PartInfo>
 
Paul, two points to make life easier...

1. If you need to build a series of tests that all use the same parameter, consider using the store# and load# feature. We have a total of 100 "Registers" in which we can store variables and/or computed values.

So, instead of repeating the same parameter, you could do something like this:

Code:
     (A:AIRSPEED INDICATED, knots) s0 110 &lt; if{ 0 }
     l0 110 &gt; if{ 148 }
     l0 130 &gt; if{ 290 }
     l0 150 &gt; if{ 432 } 
     et cetera...
In the first line, I've stored the variable into register#0, and in the remaining lines I've loaded the stored value from the register#0! :cool:

Note also that the els{ } has been omitted entirely since it's unnecessary...

2. The only real difference between <Sim> and <Code> is one of structure. I rarely use <Sim> because it is not nearly as flexible as a <Code> format.

The two following snippets of script are functionally identical:
Code:
      <Parameter>
        <Sim>
          <Variable>PLANE HEADING DEGREES GYRO</Variable>
          <Units>degrees</Units>
          <Scale>1</Scale>
          <MinValue>0</MinValue>
          <MaxValue>360</MaxValue>
        </Sim>
      </Parameter>

Code:
      <Parameter>
        <Code>
            (A:PLANE HEADING DEGREES GYRO,degrees) 360 min 0 max
        </Code>
      </Parameter>
 
Last edited:
Back
Top