Language:
Page Info
Tags:
Skill Level:
Engine Version:

Using Motion Controllers

Choose your OS:
Prerequisite Topics

This page assumes you have prior knowledge of the following topics. Please read them before proceeding.

Adding Motion Controller support to your UE4 projects can add a level of real sense of immersion and realism. One way to take this immersion and realism to the next level is add the ability to pick up objects placed in the world with your Motion Controllers. In the following document we will take a look at how you can add Motion Controller support your UE4 VR project.

Motion Controller Setup

In the following sections we will go over how to setup your Motion Controllers so that they can pick up and drop items that are placed in the level.

Component, Variable, & Event Setup

Before we can start to add nodes to the Event graph, we first need to create and set up a few Components and Variables. In the following section, we will go over what Components and Variables are needed and what setting they should have.

Component / Variable Type

Name

Value

Scene

HeldObjectLocation

X: 38, Y: 0, Z: 0

Boolean

IsHoldingObject

false

Click for full image.

Make sure that the Held Object Location is parented to the MC_Left as this is where the picked up object will be placed when picked up.

You will also need to create two Custom Events and name them the following:

Node Name

Value

PickUpObject

N/A

DropObject

N/A

HT_Using_Touch_06.png

Holding and Dropping of Items

The Holding and Dropping of Items section call the different Custom Events that handle picking objects up and holding objects as well as dropping them. The user initiates this by pressing or releasing the Left Motion Controller Trigger. One thing to take note of here is that we are using a Branch statement to make sure that we can only pick one object up at a time. The reason this is important is we only want the user to be able to pick up one object at a time.

Copy Example

HT_Using_Touch_00.png

Click on the Copy Node Graph in the upper left hand corner to copy the Blueprint code for this section.

Pick Up Object Event

The Pick-Up Object Event section handles all of the logic for finding objects that can be picked up and picking them up. While this is one function, it does have two parts that it can be broken down into. In the following section, we will take a look at these two parts and what they do.

  1. The first part of the Pick-Up Object Event deals with finding the object in the world that meets the requirements for being picked up. To do this, a ray is cast 1,000 CM into the world from the forward facing direction of the user's Left Hand Motion Controller. This ray is also told to ignore any object that does not have an Object Type of Physics Body.

    Copy Node Graph

    Click on the Copy Node Graph in the upper left-hand corner to copy the Blueprint code for this section.

    For testing purposes, the Draw Debug Type has been set to Duration allowing us to the ray that was cast into the world. When you are ready to use this in production, make sure to set the Draw Debug Type to None.

  2. The second part of the Pick-Up Object Event deals with what happens once we find an object we can pick up. When an object is found the Break Hit Result node is used to get more information about what we hit. In this case, we are using it to find out what Actor and Component where hit. Physics is then disabled on that object, and the object is then attached to our Held Object Location that is attached to our Left-Hand Motion Controller. Finally, we set the variable IsHoldingObject to true so that we can not pick something else up.

    Copy Node Graph

Drop Object Event

The Drop Object Event section handles all the logic for dropping objects that have been picked up and also making sure that everything is reset, so we are ready to pick something else up.The first thing that the Drop Event does is check to make sure that the user is holding something that can be dropped. If they are holding something, then that object is then detached from their Motion Controller and has its physics re-enabled allowing it to fall to the ground. Finally the Hit Component and Picked Up Actors variables are cleared of any old data making sure they are ready to store the newly picked up object.

Copy Node Graph

Completed Blueprint

With the Blueprint now complete, we just need to add some objects to the world to pick up. Since the objects we are looking to pick up must have a physics body, you can just add a few Static Mesh and set their Mobility to Movable and also make sure to enable Simulate Physics.

Click for full image.

Then place the VRPawn in the world and make sure to set Auto Possess Player to Player 1 and launch your project using the VR preview. Next, put on your Rift HMD and pick up your Touch controllers and aim the Left Touch Controller in front of an object you want to pick up and squeeze the trigger to pick it up. Release the trigger to drop the object and pick up another one like in the following video.

Below you will the completed Blueprint which you can copy and paste into your VRPawn Blueprint should your not be working, or you would like to use this in another project. Remember that when you do copy over to a new Blueprint, you will need to create all of the required Variables and Components.

Copy Node Graph

Click on the Copy Node Graph in the upper left hand corner to copy the Blueprint code for this section.

UE4 Project Downloads

Below you will find a link to where you can download the UE4 project that was used to create this example.

Tags