Unreal Engine Virtual Reality Quick Start Guide by Jessica Plowman

Unreal Engine Virtual Reality Quick Start Guide by Jessica Plowman

Author:Jessica Plowman [Jessica Plowman]
Language: eng
Format: epub
Tags: COM087020 - COMPUTERS / Desktop Applications / Design and Graphics, COM057000 - COMPUTERS / Virtual Worlds, COM051240 - COMPUTERS / Software Development and Engineering / Systems Analysis and Design
Publisher: Packt
Published: 2019-02-28T07:36:44+00:00


The Teleport function

Before we move on to the TraceActivateUp, we need to create a function that can handle the mechanics of the teleport. Over in the Functions section of the My Blueprint panel, click the + button and name the new function Teleport Player. Teleport Player needs to have a couple of input values to work. The first is named Player and will be of the type Actor. The second will be named Loc and this will be of the type Vector.

The teleport itself will require a little bit of math and will need a bit of info from our Player Controller. Let's start the sequence by dragging an execute line from the function node and dropping it to open the search menu. Search for the Cast to PlayerController node and create it. Casting allows us to pretend to be another blueprint and is just one of many ways that allow us to communicate data between blueprints.

Casting requires an Object input, a reference to the specific object we're pretending to be to access its data. To get the exact PlayerController we need, click and drag a line off the Player input on the function node and drop it. Search for the Get Controller node and connect its output to the input on the Cast to PlayerController node.

Next, create a SetActorLocation node. This will do the actual teleporting by moving the player to the designated vector coordinates. Connect the execution output from the cast into the execution input on SetActorLocation. The target input should be set to the Player by dragging a connection from the Player input on the function node to the Target input on SetActorLocation.

It's now time to calculate the new location! To start, we'll need to get the location of two things: the player and the player camera. To get the player's location, drag a line off the Player input on the function node and drop it to open the search box. Search for the GetActorLocation node and create one. We'll need this data in a moment.

Drag a line off the as Player Controller output from our Cast to PlayerController node and use it to search for the Get Player Camera Manager node. Drag off the output of that and search for the Get Camera Location node.

Here is the math part: We need to subtract the location of the player's camera from the location of the player itself to find the true location of the HMD for our teleport. For that, we'll need a Vector - Vector node. The top input will be the vector output from our GetActorLocation node. The bottom input will be the vector from the GetCameraLocation node.

We're almost there! Right-click on the output pin of our Vector - Vector node and split the struct pin. We only need the X and Y value for the next part of the calculation. Create a new Vector + Vector node and split the struct pin on the top input. Connect the X and Y output values from Vector - Vector into the X and Y input values on the Vector + Vector node.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.