AI groundvehicles

From FlightGear wiki
Jump to navigation Jump to search
The AirTrain at KSFO.
Steam train

Groundvehicles can be anything, from trains to busses to cars.

The in this article shown examples are based on the SFO AirTrain scenario, included in FlightGear 2.0.0 and later.

The model

Create a .xml file for your model, preferably in $FG ROOT/Models/Transport/. The minimum required content will be similar to:

<?xml version="1.0"?>

  <enable-hot type="bool">false</enable-hot>


  • The path is relative to the directory that the .xml file is located.
  • The range animation can be left out, but it will improve our framerates a little, as the model will be hidden when the viewer is 20000 meter away. For small vehicles this can be significantly less than, as they won't be visible from large distances anyway.
  • For the moment the enable-hot workaround is neccesary, in order to stop the vehicles from climbing into the air. This might become redundant one day.

The flightplan

Altough our vehicles are groundbased, they need a flightplan (= route). Flightplans are saved in the $FG ROOT/AI/FlightPlans/ directory.

Some neccesary content:

<?xml version="1.0"?>

Now we start on the actual route. A route exists of waypoints. The train will calculate its own (shortest) route between the current and next waypoint. The shorter the distance between waypoints, the more accurate the train will follow the track. However, if the distance is too small, the train will miss waypoints and go off track.

It is advised to cut the route into several sections. This will ease the bugtracking, as FlightGear does not tell you what line to look if an error occurs.

  • name: name of the waypoint. This can also be the name of a station, which will ease bugtracking later on.
  • lat: the latitude coordinate of the waypoint.
  • lon: the longitude coordinate of the waypoint.
  • alt: altitude above sea level in feet. Redundant when on-ground=true.
  • ktas: the speed in knots. The train will accelarte/decelerate after passing the waypoint.
  • on-ground: true if te vehicle should calculate its altitude based on scenery objects (it will drive on top of them).

Special waypoints

There are a couple of special waypoints.


The following will stop the train, which is useful at stations to (un)board passengers/load:

  • time-sec: time in seconds that the train will wait before driving to the next waypoint.


If your vehicle should drive through (or underneath) buildings, bridges etc. you have to add tunnel waypoints. The tunnel waypoint must be added after the entrance waypoint and after the exit waypoint.


All waypoints within the tunnel (so including the ones in front of the tunnel waypoint) should have on-ground set to false and an altitude specified.

If your entire route can be considered as a "tunnel" you can also set <tunnel>true</tunnel> in the scenario.


Every route should end in a END-waypoint. When this waypoint is reached, the train will be removed or set back to the starting point (we will define this in the scenario file).


Close the file with:


The scenario

Create a .xml file in FlightGear's $FG ROOT/AI/ directory. This is the main file of the scenario, as FlightGear will look into it to see what else to load.

The first lines of the file are general:

<?xml version="1.0" encoding="iso-8859-1"?> 

Now we can add the actual content.

  • model: the full path to the .xml file of the model that we created earlier.
  • name: the name of this piece of the train. If you have a train with multiple cars, each car needs its own name.
  • flightplan: file name (including .xml format) of the flightplan (= route) that the vehicle should follow. Each train can have its own flightplan, but all cars of the same train must share a flightplan.
  • tunnel: set to true if the train starts where there is scenery overhead e.g a tunnel or terminus.
  • restart: after the last waypoint of the flightplan is reached, the model will be destroyed (<restart>0</restart>) or placed back on the starting waypoint (<restart>1</restart>).
  • speed-constant: speed increase/decrease in kts/sec.
  • contact-offset: define the points at which ground elevation is measured for pitch calulations in ft from the origin. Negative is forward. z and y components are not (yet) available. When x=0 no pitch calculations are performed.
  • hitch-x-offset: the distance in feet from the model origin to the hitch/coupling of the next car. Only required on trains with multiple cars.

Close the file with:



  • My trains are climbing on top of eachother
    • Make sure you added the disable-hot animation to the model (see #The model).
  • My framerate is low
    • Make sure you have less than 10 ground vehicles active at any one time. (Each coach/wagon in a train or articulated truck counts as 1.)