Goblins! VR - Implementation Guides: Fixed-movement VR levers


Goblins! VR: Implementation bits and pieces

Part 2: Fixed-movement levers

This post goes over the UE4 Blueprint method used in Goblins! VR to create a fixed-movement lever, used in the game as a naturalistic volume controller/fader on the hi-fi unit (figure 1). With this lever, the player can adjust the music and sound effects levels at any time during play.

Figure 1. The hi-fi volume fader model in-game

Setting up the lever actor

To start, I created a new BP actor (right click in content browser – Blueprint Class – Actor) then opened it up (figure 2). In the static mesh component settings panel, I added my basic model and materials for the lever.

Figure 2 shows the settings for the actor (self). The main feature here is the input section, where Auto receive Input is set to Player 0. The physics and collision settings I used for static mesh component are in figure 3.


Figure 2. BP actor main window

Next, I added (parented) a box collision component to the static mesh component – this would be the proximity trigger that would respond to the player. I made the box a little larger than the mesh handle to give the player a bit of leeway as picking up objects in VR can be tricky for beginners.

For the box collider, I used the default settings so you shouldn’t have to change anything there.

            

 

Figure 3. Settings used for physics and collision on the static mesh component

BP script for the lever actor

In the event graph of the lever actor, I added the following BP script (figure 4). The general idea is that when the player’s VR controller is touching the lever and they hold down the trigger, they can then move the lever but only along a single axis with clamp limits in both directions.


Figure 4. Overview of BP for lever

Starting at the left side of the BP, the box collider gives us Component begin and end overlap events and a gate to check if the player’s controller is touching.

The player’s controller trigger is connected (via the BP Motion Controller actor – automatically made in UE4 if you’re using the VR template) to the custom event activate. This then goes through the gate to a get all actors of class node – the actor class for this node was set to BP Motion Controller.

The basic idea is to get the location of the player’s controller to determine the location of the lever.

Setting the lever’s location

Dragging out from the Get all actors of class node, I then accessed the selector component of the player’s controller (figure 5)


Figure 5. Player’s controller (the selector is the sphere at the front)

From this component, I then got its world location from which I took only the X axis data (see figure 6). This is because I only wanted the lever to move forwards and backwards which, relative to the way the hi-fi was facing, meant I needed the X value.

Figure 6. Setting the lever’s location

Using a clamp(float) node, I set min and max values that limited how far the lever could be moved in either direction.

To figure out these values, I simply went into the editor and moved the lever into the positions I wanted it to be in to represent 100% and 0% volume. Then I took a note of the X values and entered them into the clamp(float) node.

You can see in figure 7 how the X value in the editor transform window (1570) – as the lever is in its ‘fully up’ position – matches the max value in the clamp(float) node.

Of course the orientation of your lever may be different. This will change not only which axis you need to get data from but also whether the min and max values equal the lever’s bottom and top positions respectively, or whether these values need reversing.

A bit of trial and error is required.



Figure 7. Using X value in editor to enter clamp float values

After the X values are sorted, the Y and Z values are taken from the get actor location node of the lever itself. This fixes the other 2 axes, so the player can only move the lever along a single, specified axis (in this case X).

The values are then brought together and sent into a set actor relative location node which updates every frame unless the player releases their trigger (which triggers the deactivate custom event – see figure 4).

The next guide will look at connecting the lever to the music volume and the hi-fi display

Get Goblins! VR

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.