Categories
Uncategorised

GD2 Blog: Week 3

Unreal and C++

As of the 18th of October, we continued from our previous Unreal Project to add some pickups to our game that would affect and change the player. The following pickups would change the player’s speed, scale and also health.

To do this, I created a base Pickup actor that would then be the parent to multiple different other pickups that’d override the original code of the parent.

To make sure the pickup works, we use a begin overlap function within the code which detects whether the pickup overlaps the player.

“Event called when something starts to overlaps this component, for example a player walking into a trigger. For events when objects have a blocking collision, for example a player hitting a wall, see ‘Hit’ events.”

docs.unrealengine.com (2021)

In the code of the pickup contains an OnOverlapBegin function where the effects of the pickup take place, this then casts it to our character so we are allowed to change their variables with a pointer.

Also included in its tick function is also some code that enables it to rotate on the spot – this makes it stand out to the player.

Figure 1

Once the pickup was done, it was now time to create some children based off of it. The first one I did was a health pickup, which would simply add 50 onto the player’s health variable and then destroy the pickup.

Also included is UE_LogTemp, which sends a warning to the Output log which is what we’ll be using to test if the function works properly.

Figure 2

Below shows before the player overlaps with the pickup, so far they are down to 50 health as shown by the widget.

Figure 3

Once walked over, we get confirmation of the overlap from our UE_LogTemp from before.

Figure 4

Once collected, the pickup disappears and 50 is added onto the player’s health.

Figure 5

Here is the code to one of the other pickups, this one scales the player on overlap by enabling a boolean from the character’s code that enables a certain function within it.

Figure 6

The pickup has a different shape to the health pickup to help further distinct it, on overlap the player immediately scales upward.

Figure 7

The next pickup is a speed one, this simply increases the speed of the player. Unlike the other pickups it has text above it to further define what it is.

Figure 8

Like the others, it simply changes one of the player’s variables. In this one it sets the player’s speed from 0.3 to just 1.

Figure 9

After managing to create some simple pickups, I feel as if I’ve gotten a better handle on using pointers with casting in Unreal.

Bibliography

Docs.unrealengine.com. 2021. On Component Begin Overlap. [online] Available at: https://docs.unrealengine.com/4.26/en-US/BlueprintAPI/Collision/OnComponentBeginOverlap/ [Accessed 25 October 2021].

Leave a Reply

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