GD2 Blog: Week 22

Collaborative Project

As of the 21st of March, I decided to work more on the collaborative project using Unreal Engine 4.

After implementing some basic movement and trigger activated camera angles, I implemented a health and damage system using projectiles on the player to test it.

As shown in Figure 1, there is a widget that displays the player’s health and a projectile spawner represented as a small cube. Projectiles come out, and once they overlap with the player they deal damage.

Figure 1

First off, I set up a Projectile actor using a sphere component for collision, a projectile movement component and a mesh component (See Figure 2).

“ProjectileMovementComponent updates the position of another component during its tick.”

docs.unrealengine, 2021

The projectile movement component enables me access to plenty unique functions that will allow our projectile to shoot forwards – these are applied every tick within the game.

Figure 2

Included in Figure 3 is the constructor of the projectile. Here we are setting up our collision component’s body and collisions – we also give it an OnComponentHit event which allows us to call a function whenever the projectile collides and hits an object.

There are also settings for our Projectile Movement Component, for the purpose of the game, I set the speeds of the projectiles to low numbers as to make them easier to dodge within a bullet hell setting.

Then there is the set up of the mesh component, this is purposefully left unassigned as we’ll be using blueprints to assign the mesh instead. Very briefly we also set the initial life span of the projectile to 3 seconds, this simply destroys our projectile after a certain amount of time – this will be useful for optimization reasons as to not have too many active projectiles at once for too long.

Figure 3

Once the projectile was set up, I started to work on a spawner that’d spawn projectiles on a looped timer that’d constantly shoot projectiles.

In the header file, I’ve included UPROPERTIES that declare the spawner’s Offset, TSubClassOf (This allows us to select a class that our spawner spawns) and Mesh Component.

Included near the bottom is our Timer Handle, which will be used later on in our CPP file (See Figure 4).

Figure 4

In the Beginplay function, we set a timer that initiates a shoot projectile function. The projectile spawns at a frequency set from a float variable – this being the Projectile Spawn Speed.

The looping part of the timer is set to true, and the first projectile will spawn in 0.5 seconds (See Figure 5).

Figure 5

The shoot projectile function allows our spawner to spawn a projectile at its current location and rotation (This is so we’re able to rotate which direction the spawned projectiles can go in).

Included is a spawn offset, as well as getting the spawn parameters for our projectile (See Figure 6).

Figure 6

Within the blueprint version of our spawner, we’re able to set the TClassActor to our BaseProjectile from earlier.

Figure 7

Next up is the implementation of adding in a widget that simply displays player health, inside the widget display is a couple of text boxes, one has a set binding to it as seen from the highlighted box (See Figure 8).

Figure 8

In the event sheet, we set our bind to cast to the player character, we then get the health variable and link it to the return node (See Figure 9).

Figure 9

In our player’s code, I have an OnOverlapBegin function set up that detects whether the player is being hit by a projectile or not – once hit, the player will lose health and the projectile will be destroyed (See Figure 10).

Figure 10

Within the player’s constructor is a set up for their health and an onDestroyed event for which will get triggered once the player loses all their health (See Figure 11).

Figure 11

So far, player health is kept track by a tick function. It constantly checks every frame to see if the player health is equal to 0, if it is, then the player will be destroyed (See Figure 12).

Figure 12

Once the player is destroyed, this function will then be activated. So far we have a debug message display instead to make sure the code works (Figure 13).

Figure 13

In-game, once the player collides with the projectiles, their health will subtract (See Figure 14).

Figure 14

Once the player’s health drains down to 0, they will be destroyed – once destroyed our debug message will display in the upper left corner (See Figure 15).

Figure 15

So far, I’ve managed to successfully implement a basic system for damage and gameover conditions. Afterwards I may need to consider some more elements, such as respawning the player at checkpoints and include ways for them to refill their health.

Bibliography 2022. UProjectileMovementComponent. [online] Available at: [Accessed 5 April 2022].

Leave a Reply

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