Building the UT Translocator using UE4 Blueprints - Part II

Alright, so we're back again to continue from where we left off with our tutorial on building a Translocator in Unreal Engine. In the first part of this tutorial series, I had gone over the design process behind creating the Destination Module for the Translocator. Now we're going to create the other half of the device: the Source Module.

The Source Module has two fire modes: the Primary Fire mode which can be used to launch as well as retrieve back the Destination Module, while the Alt-Fire mode teleports the player to the Destination Module (and retrieves it in the process). So that's what we're going to implement in this second and final part of the Translocator tutorial. So without further ado, let's get started.

First, let us create an actor blueprint for the Source Module and set up its default properties. Once you're created the blueprint, open it, click on the Add Component button and add a Static/Skeletal Mesh Component (choose one based on your weapon mesh type). Since the mesh is not going to be interacting with anything, we can set its CollisionEnabled parameter to No Collision. Next, add an Arrow Component and adjust its relative location until its right where you want to Destination Module to be spawned. Finally, let's add a new boolean variable and call this bTranslocatorFired.



Now that we have all the necessary components & variables set up, let's move on to the Event Graph. If you've played the original Unreal Tournament, you would have noticed that the Destination Module of the Translocator also gets spawned you equip the device. So that's what we're going to do first. In the Event Begin Play, we'll spawn in the Destination Module and attach it to the Arrow Component added in the previous step.


Before moving on to the primary and alt-fire logic, we will first add a separate event to retrieve the destination module & reset the Translocator to its default state. Let's call this event RetrieveDestinationModule. This event will be called as part of both the Primary as well as Alt-Fire logic. To start things off, we want to reset the Destination Module to its default state. But since we've already implemented the required logic for this in the first part of the tutorial, all we have to do now is call the Reset event in the Destination Module. Next, we set its actor rotation to match the player camera rotation in order to make sure that it aligns perfectly with the Source Module before snapping back in place. Finally, we wrap up the event by setting the variable bTranslocatorFired to false.

 
Now let's start with the Primary Fire implementation. We'll create a new event PrimaryFireTriggerPressed for this. Since it works differently based on whether the Destination Module has been fired or not, we're going to first check that by passing our bTranslocatorFired variable through a Branch node. If it hasn't been fired already, we detach the Destination Module, call its Launch event and set the value of bTranslocatorFired to True. If on the other hand, it has already been fired, we call the RetrieveDestinationModule event created in the last step, thus priming the Translocator to be fired again.


And so we arrive at the final piece of logic within the Translocator's Source Module: the Alt-Fire mode. Similar to the Primary Fire, we'll start with creating a new event AltFireTriggerPressed, followed by checking if the device has been fired already. If yes, then we'll Teleport the player pawn over to the location of the Destination Module, and follow it up with a call to the RetrieveDestinationModule event.


At this point, you should have a working Translocator at your disposal. But I'll also briefly show you how your player character can interact with it. In the Event Begin Play of your player character, use the SpawnActorFromClass node to spawn an instance of the Translocator, store a local reference to it, and attach it to your character mesh component.


Now it's just a matter of getting the Translocator reference and calling its Primary and Alt-Fire events for each of the associated input action events.

 
Here's a video showcasing the final result of what it should look like (ignore the lights & antenna on the Destination Module, they're something I just added for show)



And thus we finally come to the end of this tutorial. I'll be sharing the project files on GitHub soon. Will update the link over here once it's done. Apart from that, I'm also planning to write an article on using EQS to create 2D Line of Sight Visualizations in Unreal. So if that's the sort of thing you're interested in, keep an eye out for it in the upcoming week.

Comments