GD2 Blog: Week 16

Unreal Hovercraft Game

As of the 17th of January, I’ve decided to redo the hovercraft game from before but in mostly C++ this time instead. I’ve also added a level and some simple mechanics (See Figure 1).

Figure 1 (Personal Collection)

The objective of the physics game is very simple, in that the player is given the task to collect 10 cube pickups as hinted at by the game’s hud. The player must traverse through the obstacle course using the hovercraft to find these.

To help assist the player throughout this course, I’ve included details such as this one in Figure 2. On the hovercraft are back and front lights, the back lights of which turn on as a bright red from the player moving backwards – similar to how a car works.

This is to help the player to discern what type of direction the hovercraft is pointed towards, as its fairly simple shape might disorient players on which way it is facing.

Figure 2 (Personal Collection)

Within the constructor code of the hovercraft, I’ve created several properties that attach themselves to the front and back of the hovercraft – these being spotlight components.

The backlights start with an intensity of 0 as to look turned off (See Figure 3).

Figure 3 (Personal Collection)

In the player input functions, going backwards sets the light’s intensity to 10,000, and once released sets it back to 0.

Included are also several debug messages from GEngine to help notify me whether the inputs go through or not (See Figure 4).

Figure 4 (Personal Collection)

As the game is based around a hovercraft, physics is simulated on the player. How the player moves around is by using forces to push it around, this is done with several float variables to determine the speed (See Figure 5).

Figure 5 (Personal Collection)

These floats as seen from earlier on Figure 4 are changed depending on the player’s inputs, if the hovercraft goes forwards or backwards it moves forward by an applied force – once released however it gets set to 0.

How it starts to move is that within the tick function, there is a constant force being added every frame. This takes the force from our variables and multiplies them with the actor’s forward or up vector (See Figure 6).

Figure 6 (Personal Collection)

GetActorForwardVector just simply gets our actor’s forward vector within the world space, this means that the force will be applied to whichever way the actor is facing.

“Get the forward (X) vector (length 1.0) from this Actor, in world space.”

(docs.unrealengine, 2022)

Our GetActorUpVector is quite similar, in that it gets our actor’s Z position, we apply our turn torque force to this as to get it to rotate.

“Get the up (Z) vector (length 1.0) from this Actor, in world space.”

(docs.unrealengine, 2022)

One problem with being physics simulated however is that the player is liable to fall over onto their side (See Figure 7).

Figure 7 (Personal Collection)

To help solve with this I have a simple input that allows the player to restart their current rotation and immediately stand the hovercraft upright.

As seen in Figure 8 I have created a function that once pressed sets the hovercraft’s relative rotation to reset every axis but their yaw – this is just to not reset which direction the player is facing.

Figure 8 (Personal Collection)

Spread around the course are also pickups which once collided with the player simply add up to the pickup count and disappear.

Figure 9 (Personal Collection)

Within the code, this is done using casting. The hovercraft is referenced in the Pickup’s header file alongside with a void created for the overlap event (See Figure 10).

Figure 10 (Personal Collection)

As shown in Figure 11 is the cpp file of the pickup, within the constructor a UBoxComponent is created for the hitbox of the pickup and has their collision set to “Trigger” – also included is a function to allow the hovercraft to overlap it.

As the game begins, it instantly casts to our hovercraft, once it overlaps we check to see if it is the hovercraft and call a function within it to take up the pickup. The pickup is then called to destroy itself as to appear as if the player is taking it (Figure 11).

Figure 11 (Personal Collection)

Once this function is called, it simply adds a total of plus one to our player’s pickup total and displays a debug message to confirm that the call worked (See Figure 12).

Figure 12 (Personal Collection)

Within the widget blueprint of the game, there’s a binding attached to a number counter which displays the same variable (see Figure 13).

Figure 13 (Personal Collection)

Within this binding is a blueprinting function that casts to our hovercraft and simply gets the total pickups variable to display onto the return node (See Figure 14).

Figure 14 (Personal Collection)

This newer and current version of this hovercraft mixes in both C++ and Blueprinting code from the previous version, I think with what I was able to translate and convert from the tutorial into C++ wasn’t too bad.

Although only the hover components themselves are blueprinted the exact same from the previous game, I was able to get blueprints and C++ code working together – this could potentially be a useful and versatile skill if you were working in a group with non-programmers as to allow them to edit your game easier.

Bibliography 2022. Get Actor Forward Vector. [online] Available at: [Accessed 23 January 2022]. 2022. AActor::GetActorUpVector. [online] Available at: [Accessed 23 January 2022].

Leave a Reply

Your email address will not be published. Required fields are marked *