Howto:Adding gun effects

From FlightGear wiki
Jump to navigation Jump to search
The F-105 in action.

With Flightgear's increasing capabilities, bullet effects such as tracers and smoke on impact are now supported. You will need FlightGear version 1.9 or later, in order to use the effects.

Setup

There is no default key/button binding for a trigger in FlightGear, so you will have to make your own. An obvious choice of button would be the trigger on a joystick, but you can also make a keyboard binding by adding something like this to your $FG_ROOT/keyboard.xml file:

<key n="101">
 <name>e</name>
 <desc>Gun Trigger</desc> 
  <binding>
   <command>property-assign</command>
   <property>controls/armament/trigger</property>
   <value>true</value>
  </binding>
 <mod-up>
  <binding>
   <command>property-assign</command>
   <property>controls/armament/trigger</property>
   <value>false</value>
  </binding> 
 </mod-up>
</key>

In the code, we have used e as the trigger. You can change it to a choice of your own but e is the standard key binding used by most aircraft in FlightGear. Joystick bindings are a bit more complex, but are explained in the wiki article on Joysticks.

See more complex/complete sample code below.

Adding guns and bullet effects to your Airplane

Once you have a key or button binding defined to active the trigger, you'll then need to add the needed AI_Systems#Submodels configuration file to your airplane's root directory, and ensure the file is activated in your *-set.xml file. The choice of tracer, smoke and impact visual models is up to you. You may also add a sound effect to your sound configuration file that activates with the trigger.

The standard trigger location for FlightGear is

/controls/armament/trigger

To add triggers for more than one weapon:

/controls/armament/trigger
/controls/armament/trigger1
/controls/armament/trigger2
etc.

In a submodel.xml file, this typically looks something like this:

   <submodel>
   <name>cowl-guns-bullets</name>
   <model>Models/Geometry/null.ac</model>
   <trigger>/controls/armament/trigger</trigger>
   . . .

Aircraft already equipped with guns

Some aircraft have the needed submodel files included. All aircraft equipped with guns in Dave's hangar are capable bullet effects. Like:

Other aircrafts (not from Dave's Hangar) include

Current limitations

  • Submodel information is not sent with the multiplayer protocol, so multiplayer users will not be effected by your bullets. The tracers, smoke and impact effects will only be seen by you.
  • The impact cylinder for models is fairly large, so you will see impacts occur outside of the target model's boundaries.

More complex/complete sample keyboard code

Different FlightGear aircraft use different locations for the main armament trigger. Two locations are commonly used:

 ai/submodels/trigger
 controls/armament/trigger

The following code, which you can place in your keyboard.xml file or (if you are an aircraft designer) in your aircraft's -set.xml file, triggers both of those locations and works with almost all FG aircraft:

     <key n="101">
        <name>e</name>
        <desc>Gun Trigger</desc> 
        <binding>
         <command>property-assign</command>
         <property>ai/submodels/trigger</property>
         <value>true</value>
        </binding>
        <binding>
         <command>property-assign</command>
         <property>controls/armament/trigger</property>
         <value>true</value>
        </binding>
        <mod-up>
         <binding>
          <command>property-assign</command>
          <property>ai/submodels/trigger</property>
          <value>false</value>
         </binding>
         <binding>
         <command>property-assign</command>
         <property>controls/armament/trigger</property>
         <value>false</value>
        </binding> 
        </mod-up>
     </key>