Howto:Animate canopy or doors: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
mNo edit summary
(add link)
Line 2: Line 2:


Create a canopy object that uses the method in aircraft.door for animation.
Create a canopy object that uses the method in aircraft.door for animation.
In a Nasal file of the aircraft that loads at start-up add:
In a [[Nasal]] file of the aircraft that loads at start-up add:
<syntaxhighlight lang="php">
<syntaxhighlight lang="php">
var canopy = aircraft.door.new ("/controls/canopy/", 5);
var canopy = aircraft.door.new ("/controls/canopy/", 5);

Revision as of 18:08, 13 March 2015

Example: A canopy

Create a canopy object that uses the method in aircraft.door for animation. In a Nasal file of the aircraft that loads at start-up add:

var canopy = aircraft.door.new ("/controls/canopy/", 5);

This creates a node in the property tree that contains two properties, /controls/canopy/position-norm and /controls/canopy/enabled, and sets the transition time to 5 seconds.

In the model file add the animation:

 <animation>
  <type>rotate</type>
  <object-name>canopy</object-name>
  <property>/controls/canopy/position-norm</property>
  <factor>55</factor> <!-- The rotation in degrees -->
  <center>
   <x-m>-2.7165</x-m>
   <y-m>0.0</y-m>
   <z-m>1.2040</z-m>
  </center>
  <axis>
   <x>0</x>
   <y>1</y>
   <z>0</z>
  </axis>
 </animation>

In the -set file add a binding to open/close the canopy. Eg.

	<key n="4">
		<name>Ctrl-d</name>
	        <desc>Toggle Canopy</desc>
	          <binding> 
	          	<command>nasal</command>
			<script>MyAircraft.canopy.toggle();</script>
		  </binding>
	</key>

The Nasal code runs the toggle method of object canopy created above.