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].

Categories
Uncategorised

GD2 Blog: Week 2

Unreal and C++

As of the 11th of October, we started to work on importing models and animations into Unreal, and making them function in-game. For this we created a PlayerController class that would be using inputs to move.

Additionally, I’ve also used an Animation Blueprint to make the animations function through movement.

First off, we had to set the input mappings within the project settings. For walking movements, we use the Axis Mappings which are continuously held down by the player (See Figure 1).

“The inputs mapped in AxisMappings are continuously polled, even if they are just reporting that their input value is currently zero.”

Docs.unrealengine.com (2021)

We will also bind some keys to these, there are also some scales assigned which is essentially what scales the value of the current input – for instance walking backwards would have a negative scale as shown.

Figure 1 (Self Collection)

In the header file of our character, we declare two void functions that will allow us to move our character.

Figure 2 (Self Collection)

In our CPP file, we use a pointer within the SetupPlayerInputComponent void to point to the inputs we created in project settings and apply them to our character’s movement voids from the header file.

Once set up, we create movement by using FVectors and then multiply the value going into the movement with the player’s speed variable.

Also using FRotators we can set our player to be facing where they are currently moving, ff the value going into the speed is greater than 0, then our player will be facing forwards.

However if it is less than 0, it will be assumed that they are going backwards and thus will be flipped

Figure 3 (Self Collection)

After importing the player’s model and animations into the game, I used an animation blueprint to make sure the player’s idle and movement animations blend and work together properly using EventGraphs and AnimGraphs

“AnimGraph to drive State Machines, BlendSpaces or other nodes; enabling blending between multiple Animation Sequences or poses that can fire off notifications to other systems, and enabling dynamic animation-driven effects.”

Docs.unrealengine.com (2021)

Using the EventGraph, I was able to create several variables that would be set by casting the character’s current rotation and velocity as seen in Figure 4.

Figure 4 (Self Collection)

Afterwards, I would create an AnimGraph that used these values to determine which animation played depending on the player’s speed.

As you can see an idle animation turns into a walk one if the current speed is greater than 0, but walking at a speed greater or equal to 10 would start the player’s walk cycle (See Figure 5).

Figure 5 (Self Collection)

Within the Player character’s code, I also created a function that would constantly scale them up and down within the header file. These variables are also going to be editable within the blueprint using UPROPERTY macros.

Figure 6 (Self Collection)

Within the header file, I also declared one more void function where the character scaling will be taking place.

Figure 7 (Self Collection)

In the CPP file, I created a function for the scale that would detect whether a boolean was enabled and how high a player’s current scale was.

If the player’s scale is higher than the set MaxScale, then scaleUp will be set to false, otherwise if the value is lower than the MinScale then scaleUp will be enabled.

Figure 8 (Self Collection)

Every tick, the character will check whether the scaleUp boolean is true or false, if it is true then the character will keep scaling up.

However if it is false, then they will simply scale down.

Figure 9 (Self Collection)

In-game, the character is now able to scale up and down constantly using CharacterScale. I feel as if this lesson was a good way to introduce us into creating our own functions, as well as further understanding how to create a Player Controlled character that can move.

Bibliography

Docs.unrealengine.com. 2021. Input. [online] Available at: https://docs.unrealengine.com/4.26/en-US/InteractiveExperiences/Input/ [Accessed 20 October 2021].

Docs.unrealengine.com. 2021. Animation Blueprints. [online] Available at: https://docs.unrealengine.com/4.27/en-US/AnimatingObjects/SkeletalMeshAnimation/AnimBlueprints/ [Accessed 20 October 2021].

Categories
Uncategorised

GD2 Blog: Week 1

Unreal and C++

As of the 4th of October, we covered using C++ and Unreal within our first lesson.

First, we covered the Unreal Engine Class Hierarchy as shown in Figure 1. This covers the different classes such as; Actors, Pawns, Characters, PlayerControllers and Game Modes.

“Selecting a Parent Class allows you to inherit properties from the Parent to use in the Blueprint you are creating.”

Docs.unrealengine.com (2021)

These are also used with C++ as well as Blueprint. These are considered the parent classes for which we will be writing our code under.

Figure 1 (Docs.unrealengine.com.)

We also made use of the UE4’s macros, which allow C++ and Blueprints to communicate with each other.

An example of one of these macros would be UPROPERTY, which is a macro you can add on the line before a class member variable.

Figure 2 (Self Collection)

What this helps enable us to do is that we are able to quickly tweak these variables in-engine using a Blueprint version of our created class using property specifiers such as EditAnywhere and BlueprintReadWrite in the brackets.

“The UPROPERTY() macro is used to expose variables to the Unreal Engine editor and to include the property in the Unreal Engine memory management system.”

Romero Blueprints (2020)

We are also able to categorize them so that they show up within the Blueprint’s properties.

Figure 3 (Self Collection)

I managed to make several different characters that would be inherit values from their parents.

For this I created a character assigned as “Animal”, and then following that created a character that inherited from this class called “Dog” which had some variables from the Animal class but also some of its own.

Figure 4 (Self Collection)

Using a UFUNCTION, I was also able to call a function that would set one of the dog’s variables to true by calling it in the default values of the class.

Also within the dog’s default values is attained from the Animal class, which is “Legs”.

Figure 5 (Self Collection)

What we learned for the first lesson was a good start to Unreal, creating simple classes and getting used to working with both Microsoft Visual Studio and Unreal.

Bibliography

Docs.unrealengine.com. 2021. Class Hierarchy. [online] Available at: https://docs.unrealengine.com/4.27/en-US/API/ClassHierarchy/ [Accessed 19 October 2021].

Docs.unrealengine.com. 2021. Blueprint Class. [online] Available at: https://docs.unrealengine.com/4.26/en-US/ProgrammingAndScripting/Blueprints/UserGuide/Types/ClassBlueprint/ [Accessed 20 October 2021].

Docs.unrealengine.com. 2021. C++ Class Wizard. [online] Available at: https://docs.unrealengine.com/4.26/en-US/ProductionPipelines/DevelopmentSetup/ManagingGameCode/CppClassWizard/ [Accessed 20 October 2021].

Romero, M., 2020. The UPROPERTY() macro. [online] Romeroblueprints.blogspot.com. Available at: https://romeroblueprints.blogspot.com/2020/10/the-uproperty-macro.html [Accessed 20 October 2021].