Creating Simple Airplane Controls

This coffeeTalk will be about creating simple airplane controls that fake break the gimbal lock.

Step 1: Introduction

Awesome! You’re here.

In this tutorial I’m going to show how to create airplane controls with blueprints in Unreal Engine 4. The result of this tutorial will be a plane that flies at a minimum speed  and can be controlled with the keyboard or a gamepad. The airplane controls are broken up into 4 parts; the project setup, the engine, the flaps and the rudder of the plane. With the tutorial I provided a paper plane mesh and a input configuration file that can be downloaded in the file section.

Grab yourself a cup of coffee and fire up the engine!

Step 2: Importing assets

The first thing we’re going to do for our airplane controls is import a mesh to represent the plane we’ll be flying. Feel free to use your own models, I provided a simple paper plane in the files section. Make sure your mesh was exported with the nose of the plane facing the positive X-axis.

So in the Content Browser click the Import button or right-click -> Import asset and select the mesh for your plane. In the import window check the box for Auto Generate Collision, leave the other settings on their default values unless you know what you’re doing. Click Import.

Continue to the next step.

Step 3: Setting up inputs

Okay, so now that we have a visual representation of our plane we have to set up the inputs for the airplane controls.

Go to Edit>Project settings>Input. Under Action Mappings add two new mappings, one called LookBack, the other one SwitchCameraMode. Unfold the mappings and add the inputs of your preference or have a look at Image01 to see how I set up the Action Mappings.

Next, under Axis Mappings add six new mappings and call them: PitchDown, RollRight, SteerRight, LookUp, LookRight and Throttle. Unfold the mappings and add inputs for positive and negative axis of your preference or look at Image02 for my set up of the Axis Mappings. 

You can also download the config file I provided in the files section and import this at the top of Inputs.

Step 4: Plane Blueprint Components and Variables

Now that we have set up our inputs we can start working on the actual plane blueprint.

In the Content Browser under Add New/right-click and select Blueprint Class. When prompted with the Parent Class window, select the Pawn class. Give your new pawn blueprint a name. I will be referring to this blueprint as BP_Plane.

Open BP_Plane and in the Components panel add the following components:

  • SphereCollision
  • StaticMesh
  • SpringArm
  • Camera
  • FloatingPawnMovement

Next make the SphereCollision into the new root by dragging it onto the DefaultSceneRoot. Parent the Camera to the SpringArm and parent the SpringArm to the StaticMesh to achieve a hierarchy similar to Image03.

Click on the StaticMesh and in the Details panel set the StaticMesh to your plane mesh. Then under Collision check the box Simulation Generates Hit Events and set the Collision Preset to Pawn.

Click on the SphereCollision and in the Details panel set the Sphere Radius so it encapsulates your plane. Then under Collision check the box Simulation Generates Hit Events and set the Collision Preset to Pawn, same as with the StaticMesh.

Click on the SpringArm and in the Details panel under Camera set the Target Arm Length to a sensible distance, e.g. 256. Then under Lag check the box for Enable Camera Lag, set the Camera Lag Speed to 6 and the Camera Lag Max Distance to 1024.

If you click on the FloatingPawnMovement you can tweak the speed settings if you want to.

Now that all the component have been added and parented we have to create a few global variables. Moving to the My Blueprint panel under variables we create a new variable and name it RollValue. In the Details panel change the variable type to float and put it in a category called Controls. Now duplicate RollValue 3 times so you have 4 float variables in total and to achieve a hierarchy in the Variables tab similar to Image04, rename the duplicates to:

  • PitchValue
  • YawValue
  • ScaleValue

Compile and save the blueprint and continue to the next step.

Step 5: Engine part 1: Add Movement Input To Plane

Now let’s create a function for adding movement to the plane. In the My Blueprint panel click Add New/+ Function and name it AddMovementInputToPlane.

In the graph of this function, right-click and search for the node AddMovementInput, which will be asking for a World Direction and a Scale Value.

Connect the execution pins.

Now right-click and search for GetActorRotation, because every Tick we want to know what the current rotation is of the plane. From the GetActorRotation return value pin, drag and release, and search for GetForwardVector, which returns the direction the plane is facing, connect the return value pin with the World Direction input from the AddMovementInput node.

The last thing we have to do in this function is drag from the Scale Value pin and search for the ScaleValue variable we created in step 3.

After we Compile the blueprint we move to the Event Graph tab and from the execution pin of the Tick event, drag and release, and search for the function we just created.

Compile and save the blueprint and continue to the next step.

Step 6: Refill your cup of coffee

Have a mini break, refill your coffee, stretch and when your ready continue to the next step of creating airplane controls.

Step 7: Engine part 2: Throttle

Cool, so, now that we’re making the plane accelerate according to the ScaleValue, we have to create a way to drive this ScaleValue with the controller.

In the Event Graph, right-click and search for Throttle and select the Input Axis Event Throttle so from it’s execution pin we can drag and release, and search for Set ScaleValue. From the ScaleValue input pin, drag and release and search for a node called Map Range Clamped, which lets us set a minimum speed the plane should maintain, so for In A and B put a value of 0.0 and 1.0 respectively,  for Out B put a value of 1.0 and for Out A you can put any value between 0.0 and 1.0. E.g. Out A set to 0.5 would result in the plane never flying slower than 50% of its maximum speed. Connect the Value pin from the node with the Axis Value from the Throttle Event.

Now that the “engine” is working, next we’re going to build the “flaps” and “rudder” of the plane.

Continue to the next step.

Step 8: Flaps part 1: Pitch

Okay, next we want to be able to pitch the plane up and down we’ll move on to the next step of the airplane controls and in order to do this we’re going to right-click in the Event Graph and search for PitchDown, pick the Axis Event and from it’s execution pin drag and release, and search for Set PitchValue.

From the PitchValue input pin we drag and release, and search for FInterp To. This node will interpolate the current value towards the target value in a smooth way. So from the Current pin we drag and release, and search for PitchValue. From the Target pin we drag and release, and search for float*float. Connect input A with the Axis Value and give input B a value of -8.0. Then from the Delta Time we drag and release, and search for GetWorldDeltaSeconds. Give the Interp Speed a value of 1.0.

From the execution pin of the PitchValue, drag and release, and search for AddActorWorldRotation. This node will ask for a Delta Rotation, which we will supply with a node called Rotator from Axis and Angle. Connect the return value with the Delta Rotation. Next, we have to get a vector and a float for the Rotator node, so off the Axis pin we drag and release, and search for GetRightVector, pick the one that has the StaticMesh between brackets. And for the float pin we drag and release, and search for the PitchValue we created in step 3.

Continue to the next step.

Step 9: Flaps part 2: Roll

Next up is rolling the plane, which enables it to rotate around its own forward axis. This will work similar to the pitch setup from step 6. First we have to search for the Input Axis Event RollRight and drag and release from the execution pin and search for Set RollValue. From the RollValue input pin we drag and release, and search for FInterp To. We connect the Current pin with our RollValue. From the Target pin we drag and release, and search for float*float. Connect input A with the Axis Value and give input B a value of 16.0. Then we connect the Delta Time to GetWorldDeltaSeconds again. Give the Interp Speed a value of 1.0.

From the execution pin of the RollValue, drag and release, and search for AddRelativeRotation. Select the one with StaticMesh between brackets. This node will also ask a Delta Rotation as well, but this time we’re going to search for MakeRotator and connect it to the Delta Rotation. Then from the X pin we drag and release, and search for our RollValue.

Continue to the next step.

Step 10: Rudder: Yaw

The last part of our airplane controls is the yaw rotation of the plane. So, we search for the Input Axis Event SteerRight. Now we do basically the same as we did with the pitch in step 6. From the Input Axis Event execution pin we get the node AddActorWorldRotation and from the Delta Rotation we get the Rotator from Axis and Angle node. From the Axis pin we drag and release, but this time we search for GetUpVector and select the one with StaticMesh between brackets. Then from the Angle pin we drag and release, and search for float*float. Connect the A input pin to the Axis Value and give the B input a value of 2.0.

Compile and save the blueprint.

Step 11: Final steps

Awesome, we’re almost there! The last things we have to do before we can start flying is making sure the player possesses the plane when we start the game and we have to alter the imported material so it will render the back faces of the plane as well. Altering the material is only for the people who used the paper plane model I provided with the tutorial.

So first the possession of the plane. In the Components panel, you can click on BP_Plane(self) which will show a global overview of this blueprint in the Detail panel. Under the section Pawn we find the option for Auto Possess Player, which is disabled by default, but we’re going to set this to Player0.

Compile and save the blueprint.

Now if we move to our Content Browser panel, we find the imported lambert1 material. Open it up and in the Detail panel, under Material, there’s an checkbox for Two Sided, make sure it’s checked so it will look like Image05.

Lastly we have to place our awesome plane in our level, so go on and put it somewhere, press Play and have fun flying your plane with these awesome airplane controls!

Gallery

Blueprints

Files

Download
Download