Blueprint Six-DOF Flying Pawn Tutorial

Rate this Page:
(2 votes)

Approved for Versions:4.0.1

Skill Level: Beginner

Engine Version: 4.0.1

Getting a 6-DOF flying pawn like in Descent is fiarly simple in UE4 using only Blueprints.

Note: If you're starting in a blank project, be sure to set up your Axis Mappings for WASD control as listed here. I'll be using the Content Examples project as it provides me with a place to fly around in and some simple assets to start with as well as the standard WASD axis bindings.

Setting up the Game Mode and Pawn
  1. Create a new Pawn Blueprint by selecting New in the Content Browser. Select Pawn from the Pick Parent Class window. Name this BP_6DOF_Pawn.
    PawnTut 010 NewBP.jpg
  2. Next, create a Game Mode Blueprint in the same manner, this time selecting Game Mode from the Pick Parent Class window. Name this BP_6DOF_Game.
  3. Now, you'll want to assign BP_6DOF_Game to the map so that you are in possession of your new Pawn when the game starts. Click on the World Settings button in the editor toolbar. This will open a tab with the map's properties. You will find a drop-down menu under Game Mode that will display your newly created Game Mode (BP_6DOF_Game).
    PawnTut 020 WorldProps.jpg
  4. Assign BP_6DOF_Pawn to the Game Mode Blueprint by opening BP_6DOF_Game and clicking on the Defaults tab and assigning your new BP_6DOF_Pawn class with the Default Pawn Class dropdown.
    PawnTut 030 GameMode.jpg

Close the Game Mode Blueprint Editor and save your work (File > Save All or Ctrl+S)

Building the Pawn
  1. Open BP_6DOF_Pawn and click on the Components tab
  2. Add a Static Mesh Component by using the Add Component dropdown.
  3. Name it BodyMesh
  4. Assign your desired Static Mesh asset to the component. I've chosen the provided UFO as it fits this example very well. An important thing to note is that the Static Mesh Component will require valid collision to work properly!
  5. In the Details panel, scroll down to the Physics section and do the following:
    1. Enable Simulate Physics
    2. Disable Enable Gravity
    3. Set Angular Damping to 1.0
    4. Set Linear Damping to 1.0
      PawnTut 040 StaticMeshDetails.jpg
  6. In the Components panel, add a new Camera Component from the dropdown. This will parent it to the BodyMesh, inheriting the movement and rotation.
  7. In the Details panel, or using the transform gizmo in the Blueprint Editor viewport, set the position of the Camera behind the MeshBody.
  8. Also, disable Use Controller Rotation as we want to follow the rotation of our Pawn, not the controller (Which tends to keep a horizontal view).
    PawnTut 050 CameraDetails.jpg

At this point, you should save your work! If you play the level (Alt-P), you should see your Pawn in front of you, but won't be able to move at all. Next, we'll get some input events and get the Pawn moving around!

Input Part 1: WASD Movement
  1. Open the BP_6DOF_Pawn editor from the Content Browser by double-clicking the icon.
  2. Go to the Graph tab and ensure you are in the Event Graph (not the Construction Script).
  3. Right-Click in the graph area and find the Move Forward Axis Event (not the Axis Value function).
    PawnTut 060 MoveForward.jpg
  4. Add a reference to the BodyMesh by dragging it from the variables list on the left into the graph and selecting Get from the menu.
  5. Drag a wire from the right side of the reference of BodyMesh, releasing the mouse in the Event Graph and find Set Physics Linear Velocity function.
    PawnTut 070 SetPhysicsLinearVel.jpg
  6. Connect the Move Forward Axis Event to the Set Physics Linear Velocity function.
  7. Drag a wire from the Axis Value node on Move Forward Axis Event, releasing on the Event Graph and select Float * Float
  8. Set the second number of the Float * Float to 30.0 to give our ship some thrust.
  9. Now, we need to add that thrust to the local X or Forward vector of our Pawn. UE4 offers a simple method for this via the Get Forward Vector function.
    1. Right-click on the Event Graph and create a Get Actor Rotation function. This returns the world rotation of the Pawn.
    2. Drag a wire from this and create a Get Forward Vector function.
  10. Multiply the Get Forward Vector return value by the multiplied Axis Value using a Vector * Float function.
  11. Send this into the New Vel node of the Set Physics Linear Velocity function.
  12. Be sure to set the Add to Current bool flag on the Set Physics Linear Velocity function to TRUE.

Your Graph should look like this:

PawnTut 080 ForwardDone.jpg

Do the same for the for the MoveRight Axis Event, using the Get Right Vector function. Your graph should look like this:

PawnTut 090 RightDone.jpg

Save your work and give it a test! You should be able to move forwards and back using the W and S keys and left and right using the A and D keys (Or, even controller input using the analog sticks!). Crashing into a wall should send you spinning! you'll need to add some steering to be able to get around without crashing.

Input Part 2: Steering
  1. Right-Click on the Event Graph and find the LookUp Axis Event.
  2. Drag a wire from the LookUp Axis Event exec node and create an Add Actor Local Rotation function
  3. Right-Click on the Event Graph and create a Make Rot function.
  4. Wire the Axis Value from the LookUp Axis Event to the Pitch node of the Make Rot function.
  5. Wire the Return node of the Make Rot function to the Delta Rotation input on the Add Actor Local Rotation function.
  6. Repeat for the Turn Axis Event
    1. Rather than the Pitch, wire the Turn Axis Event Axis Value to the Yaw.

Your Event Graph should look like this:

PawnTut 100 TurnDone.jpg

Update: one additional step that you need to do since UE4 Pawn changed and is now based of "scenerootcomponent", is to mark the mesh as root. To do so, in the components list, drag the BodyMesh onto the Scene root component to reparent it as root. Steering should now work as expected.

Save your work, close the Blueprint Editor and give it a try by playing (Alt-P).

You should get something like this: YouTube:

Input Part 3: Adding Roll
  1. Open the Project Settings dialog from the Edit menu.
  2. Go to Input
  3. Expand Axis Mappings then click the + symbol next to the words Axis Mappings. This will add a new Axis event and value to your blueprints.
  4. Name the newly created mapping Roll.
  5. Expand the Roll rollout and add another input by clicking the + next to the mapping name.
  6. Select Q for the first dropdown and set the value to -1.0.
  7. Select E for the second dropdown and set the value to 1.0.
    PawnTut 110 InputMapping.jpg
  8. Close the Project Settings dialog and open the BP_6DOF_Pawn editor.
  9. Go to the Event Graph and add the Roll Axis Event, connecting it to the Roll input of a Make Rot function.

Your Graph should look like this:

PawnTut 120 FinalGraph.jpg

Save your progress and hit Play (Alt-P). Now the Q and E keys should roll your ship!

Good luck! --Tom

Extra Credit: Physics Rotations

I figured this out, but I find that it makes the controls pretty tough to handle, however you might find it instructional on how to apply Angular momentum to the pawn. I won't go into step-by-step detail, but you can follow the attached screenshot:

PawnTut EC1 AngularVelocity.jpg