Views
Personal tools

Sliders

From X-Plane Wiki

Jump to: navigation, search

Sliders are a new feature in X-Plane 9 that let you create animation sequences based on dataref values.

[edit] The Animation Problem

3-d animation in an X-Plane object is driven by datarefs. You use a series of key frames to relate the position of your mesh to dataref values. Mesh animation and the datarefs always change in lock-step.

This means that you cannot create an animation sequence based on an instantaneous change to a dataref. Here's an example:

When the user deploys landing gear, the dataref sim/cockpit2/controls/gear_handle_down will change from 0 (up) to 1 (down). If you key frame a sequence for your landing gear off of this dataref*, you will not see the animation! Your animation sequence will jump instantly from its beginning sequence to its end!

What went wrong? The animation's time is driven off of the dataref. Since the dataref only takes on the values of 0 and 1 (with nothing in between) the animation "jumps" from start to end, showing no sequence.

Note that there is no place in the key frame system to say "how long" the animation takes in seconds. This is because the key frame system is not an event system! It does not provide a way to begin animation based on things happening in the sim - that task must be done by some other part of the sim or a plugin. Sliders are one such mechanism.

  • This is NOT a good idea - you should always key frame airframe animations off of the sim/flightmodel2/ datarefs - this example is just meant to illustrate the problem at hand.

[edit] Basic Sliders for Misc. Animation

Basic sliders are designed for animations that X-Plane does not have a native mechanism for. For example, consider a staircase deployment in a regional jet: right now X-Plane has no native support for this. You can use the slider mechanism, generic instruments, and key frame animations to make this animation sequence.

Sliders consist of two sets of datarefs and some PlaneMaker settings:

  • sim/cockpit2/switches/custom_slider_on is an array of 24 boolean values for switches that "control" slider animations. You set these datarefs using Generic Instruments (for example, the rotary switch).
  • sim/flightmodel2/misc/custom_slider_ratio is an array of 24 ratios that slowly move from 0 to 1 (and back) over time whenever the custom_slider_on switches are changed.
  • sim/operation/slider_01 ... sim/operation/slider_20 are 20 commands that toggle the custom_slider_on datarefs. This lets users bind keyboard or joystick commands to the various actions. You can also use these with Manipulators to drive your animations in 3-d.
  • Each of the 24 sliders has a "cycle time", set in PlaneMaker's systems dialog box (in the sliders tab). This controls how long it takes the ratio variable to move from its current value to the value of the switch.

Essentially, the sliders act as a time-delay mechanism, running a sequence of ratios over a set amount of time when a source switch is set. This lets you create animation sequences where you see the entire sequence.

For example, in the case of our stair case, if we want the stair case to deploy over 10 seconds, we would take these steps.

  1. We would create a staircase switch on our 2-d panel (using the generic rotary instrument) using sim/cockpit2/switches/custom_slider_on[0]
  1. We would create a 3-d staircase misc. object attached to the plane that animates based on sim/flightmodel2/misc/custom_slider_ratio[0]. It would animate from 0 to 1.
  1. We would set the cycle time for misc. slider 0 to 10 seconds in Plane-Maker.

[edit] Custom-Dataref Sliders for Specific Animation

You can also use the slider mechanism with existing datarefs.

In our previous example, we were implementing a function that did not exist in the sim at all - the staircase. We used the slider_on dataref as the "switch" to control the staircase.

What if we want to create an animation sequence for the landing lights (such as the landing light housing unfolding from the wing when the lights are turned on). We would not want to tie our landing light cockpit switch to sim/cockpit2/switches/slider_on because changing the switch would trigger the animation but not actually turn on the landing lights!

The slider system allows you to pick any dataref as a "source" for a slider, not just the slider_on datarefs (these are merely a default).

In the case of the landing lights, all we need to do is pick the real landing light switch dataref (sim/cockpit2/switches/landing_lights_on) as the source for our sliders. Now when the landing lights are turned on, our slider is triggered, and the landing lights really work.

To use a custom dataref in PlaneMaker, you first check the "customize" check-box for the slider, then pick any dataref.

In the case of our landing lights, we'd have a setup like this:

  1. In our panel, we'd have a normal landing light switch.
  2. For our slider, we'd have a cycle time of 5 seconds, customize check-box on, and a dataref of "sim/cockpit2/switches/landing_lights_on"
  3. In a misc. object for the plane we'd create a key framed animation based on sim/flightmodel2/misc/custom_slider_ratio[0] that animates the landing light housing.
Navigation
Toolbox