NWH Aerodynamics Documentation
Docs » Setup:AircraftController

Step-by-step Setup

This tutorial will describe setting up Cirrus SR22 in an empty Unity scene. The end result scene of the guide is included in the project and is named TutorialScene.

Cirrus SR22 model can be found under NWH ⇒ Aerodynamics ⇒ Models directory.

Reading the Airfoil documentation before starting the aircraft setup is highly recommended

Scene Setup

  • Create a new empty Scene.
  • Create a new empty GameObject and name it SceneManager.
  • Attach InputSystemAircraftInputProvider and InputSystemSceneInputProvider - these will handle the user input.
  • Attach ShiftingOrigin to SceneManager - more about shifting origin here.
  • Add a Terrain to the scene and position it at [-500, 0, -500] to center it.
Tutorial scene after the setup.

Aircraft Controller

  • Drag NWH ⇒ Aerodynamics ⇒ Models ⇒ Cirrus SR22.fbx into the middle of the newly created scene.
  • Select all the colliders in the hierarchy (Cirrus SR22 ⇒ Colliders) and disable/untick MeshRenderer on them. Add MeshCollider to all four. It is important that a Rigidbody has at least one collider.
Cirrus SR22 after adding MeshColliders.
  • Add AircraftController to the parent object (Cirrus SR22 in this case). This will add other required components automatically.
AircraftController and required components (automatically added).
  • In the Variable Center Of Mass inspector adjust the Base Mass to 1000 and set the Center Of Mass Offset to [0, -0.18, 0.9].
  • Untick Use Default Inertia and adjust the Dimensions field if required. Dimensions are displayed as gizmo lines. Red for width, green for height and blue for length. After adjusting the dimensions click Update Inertia Tensor.

That is it for the core aircraft setup. The next step is making the aircraft fly.

Cameras

  • Create an empty GameObject that is a child of Cirrus SR22 and call it Cameras.
  • Attach CameraChanger component to the newly created object.
  • Create a new Camera and parent it to the Cameras object and add CameraMouseDrag component to it.
  • Adjust the Distance field of CameraMouseDrag to 10.
  • Press play and check if the camera works properly. LMB to rotate, RMB to drag.

Airfoils

  • Follow the setup guide on Airfoil page to set up Cirrus SR22 ⇒ FlightSurfaces.
  • Follow the setup guide on ControlSurfaces page to set up Cirrus SR22 ⇒ FlightControlSurfaces.
  • Press play. Try pressing W and S to test out the elevators, A and D to test the ailerons and Q and E to test the rudder.
  • Place the aircraft at the height of 1000 meters above terrain and press play. Let the aircraft gain some speed and try controlling it using WASD.

Tips:

  • When setting up an aircraft the wing Airfoils should extend up to roughly the centerline of the aircraft as in the image above.
  • Airfoils should cover the control surfaces belonging to them.

To test out the setup place the aircraft 500m above the ground and press play. It should slowly tip forward and gain speed.

Once the Airfoils are set up as per the instructions above the aircraft should look like this:

Aircraft with Airfoils set up. Note the yellow lines between the airfoil (blue) and control surface (red) sections.

Aerodynamic Drag Objects

Besides airfoils aircraft also have objects that contribute little or nothing to lift, but do cause drag. In NWH Aerodynamics these can be set up using AerodynamicDragObject.

  • Attach AerodynamicDragObject component to the Fuselage object.
  • Adjust the Center and Dimensions so that the box gizmo roughly matches the shape of the fuselage.
Fuselage set up with AerodynamicDragObject.

Landing Gear

After pressing play, currently the aircraft drops to the ground. To prevent this we need to add the landing gear.

  • Add LandingGear component to LandingGear_F, LandingGear_L and LandingGear_R.
  • Adjust the Position field to match the position of the landing gear.
  • Duplicate LG_F_Wheel, LG_L_Wheel and LG_R_Wheel and rename them to LG_F_WheelCollider, LG_L_WheelCollider and LG_R_WheelCollider. Remove MeshFilter and MeshRenderer from the duplicated objects. These will act as holders for WheelCollider.
  • Drag the duplicated objects so they are slightly above the wheels.
  • Attach WheelCollider to all three duplicated objects and adjust the Radius field until the gizmo matches the wheel size.
  • Press play. The aircraft should not stand on the landing gear.
  • Assign the created WheelCollider to Wheel Collider field of LandingGear component added in first step. Also assign the corresponding wheel meshes to the Wheel field (LG_F_Wheel to LandingGear_F, etc.).
  • Set the Max Steer Angle to 10 for the LandingGear_F. This value can be set to 0 for wheels that do not steer, a positive value for normal steering, or a negative value for inverse steering (e.g. rear wheel).
  • Assign the LG_F_Cover to the Static Transform field.

The landing gear for Cirrus SR22 is now set up. For more details on LandingGear check out this page.

Landing gear after setup.
Landing gear WheelCollider gizmos.

Propulsion

The final step to setting up a functional aircraft is adding propulsion.

Cirrus SR22 is propelled by a piston engine connected to a variable-pitch propeller so PistonEngine and PropellerPropulsor will be used.

  • Under Propulsion create a new empty GameObject called Engine. This object will contain all the engine-related components.
  • Add PistonEngine to the Engine object and set the Max Power to 400 and Starter Torque to 150.
  • Add PropellerPropulsor the the Propeller object and assign it to the Propulsors field of PistonEngine.
  • If needed adjust the Thrust Point and Thrust Direction of the PropellerPropulsor.
  • Since Cirrus SR22 has a variable pitch propeller tick Variable Prop Pitch. Also tick Auto Prop Pitch.

To test the propulsion enter play mode and hold the T key for 2 to 3 seconds to start the engine. Afterwards, press F4 to increase the throttle to 100%. After gaining some speed the aircraft will be able to take off.

PropellerPropulsor after setup. The circle shows the propeller radius and the white spokes show the number of propeller blades. Red ray is the direction of the thrust.

Sound

The aircraft is now fully functional but is lacking sound.

  • Add AircraftSoundManager to the aircraft.
  • Attach EngineStartingAircraftSoundComponent and EngineRunningAircraftSoundComponent to the Engine object.
  • Attach WindAircraftSoundComponent and CrashAircraftSoundComponent to the Cirrus SR22 object. These can be placed anywhere on the aircraft.

Press play to test out the sounds.

Readouts

For testing purposes a DemoReadouts component can be helpful as it shows the basic flight data. This step is optional but recommended.

  • Create a new UI Canvas and create a child Panel.
  • Adjust the panel so that it covers the whole canvas and remove the background Image.
  • Attach DemoRedouts to the panel and set the Readout Prefab field to NWH/Aerodynamics/Scripts/AircraftController/Demo/Readout.prefab.
  • Add Grid Layout Group with Cell Size of [100, 50] to the panel.
  • Add Cirrus SR22 to the Target AC.

Pressing play will now produce a row of basic flight data readouts.

Demo readouts.

Wrapping Up

The basic aircraft setup is now finished. For steps on setting up other optional aspects of the aircraft such as lights, instruments and fuel check out their respective pages:

  • Effects
  • Instruments
  • Fuel
Previous Next

NWH Aerodynamics Documentation

Table of Contents

Table of Contents

  • Step-by-step Setup
    • Scene Setup
    • Aircraft Controller
    • Cameras
    • Airfoils
    • Aerodynamic Drag Objects
    • Landing Gear
    • Propulsion
    • Sound
    • Readouts
    • Wrapping Up
  • About
  • Import Guide
  • Airfoil
  • AircraftController
  • Environment
  • NWH Common Scripts
  • Demos
  • Upgrade Notes
  • Changelog
  • Support