Let’s suppose we are simulating a faulty fuel quantity gauge for a historic plane, the “Arbitria Examplus Mk 2”. The plane had a real fuel capacity of 200kg, but showed empty when there was 5kgs left, and full when there was 190kg in the tank. Plane Maker will provide the sim with the real fuel capacity while this animation will provide the visual realism.
First, we model a gauge and a needle, initially pointed up at 0 degrees. The texture used here is fuel_round_GA.png, included with Plane Maker.
We are using the dataref sim/flightmodel/weight/m_fuel_total. The first keyframe shows the gauge’s arrow at the empty position (135 degrees), and will be shown when the dataref is 5. The second keyframe shows the gauge’s arrow at the full position (-135 degrees), and will be shown when the dataref is 190. Here is a chart of this data as a table and graph of the arrow’s rotation over changes in m_fuel_total.
When sim/flightmodel/weight/m_fuel_total is between our explicitly created keyframes (5 and 195) it will animate as intended because X-Plane is interpolating between these known keyframes. But, beyond that X-Plane will guess by using the first two keyframes for when the dataref is less than 5 and the last two keyframes when the dataref is greater than 190. (In this case we only have two keyframes, both are used to “look ahead” and “look behind”). This is called extrapolation. Extrapolation is useful as it allows you to animate just a portion of the range of motion and allow X-Plane to do the rest. It is convenient and allows you to think of animation as incremental motion (10 degrees CCW every change of .1) that builds up dynamically rather than one large static motion that will be broken up into chunks.
There is currently a problem with our animation! We want the needle to stop moving when it reaches 5kg or 190kg, but this keyframe table will allow X-Plane to keep rotating the needle for all of 0 to 200. X-Plane’s extrapolation cannot be turned off; instead we must trick it using “clamping keyframes”. By using another keyframe on each side of the keyframe table with the same angle and a smaller and larger value respectively, we can “clamp” the animation and stop incorrect extrapolation from ruining our fuel gauge!
You can see in the graph how the extrapolation is now fooled! By giving X-Plane a flat line to follow, rather than a sloped one, past certain values the angle of rotation will stay the same no matter the dataref’s value. The value for the dataref simply has to be less than or greater than each side, but many artists use a convention to quickly identify what is a clamping keyframe. Some use -999999,999999 or adding or subtracting 1 off each end as we’ve done in this example. Both work equally well, so the real value is in being consistent. Though rarely used, it is also possible to clamp only one side of a keyframe table.
Although a rotating gauge was used, this principle applied to translations as well.
One comment on “All About Clamping Animations”
Thank you for this good description of clamping. I will now use it to prevent the ball to go outside the tube in my bank coordinator as I press one pedal to maximum extend.