Adding Functionality in the VR template

A key part of a VR experience is the interaction between the player and the objects that make up the environment. For our VR experience, the user will primarily be picking up an object that acts as an activator. For example, an object must be placed in a specific location to open a door/turn on a light.

Goal: Open a door/turn on a light when a specific object enters a trigger box.

Firstly, I created 3 Blueprint (BP) Actors with Trigger Boxes. A door, light, and any static mesh that will be used as the activator (in this case I’ve used a simple cube). The Activator BP just needs to be a an actor that has a static mesh as a child, this static mesh can be anything the user wants. The reason it needs to be a BP is so that it can be referenced in other BPs to cause events to occur. In this case I’m using Mitch’s VR Content Example scene which has preset objects and BPs that allow the user to pick them up with VR controllers.

BP Activator Setup

Next, I started working on the door. The first thing that needs to be done is setting up the rotation animation. This animation is done using a Timeline node where you can control a curve that controls the value of rotation and timing between key frames.

Timeline Node
X-axis is time, Y-axis is value of rotation in degrees

This timeline needs to be activated by an event and then this information needs to be sent to the door static mesh. However, this event can only be triggered by the activator. Below is the script of how this works.

Referencing the activator BP (IntObj = Interactive Object)
Checking if the Activator is overlapping the trigger box
Setting Rotation of Door

Logic:

  • Check if Actor overlapping trigger box is the activator
  • If true > check if closed > if closed > play timeline > change Z rotation value > Set this as the new door rotation
  • If false > Reverse animation > set this new rotation as Closed

The BP for the light is very similar. It is based on toggling the visibility of the light based on the presence of the activator in the trigger box.

Light Switch BP

This forms the basic interactions the player will do throughout the VR experience. It encourages exploration while using the movement in VR to its advantage, thus creating a much more immersive and engaging environment.