Categories
Uncategorised

GD2 Blog: Week 7

Hyper Casual Game: Part 1

As of the 15th of November, I’ve decided to work more on my Hyper Casual Game for the Unit. In this blog I’ll be going over what game I’m trying to make, and what I hope to achieve with it.

The idea for my Hyper Casual Game is to make a simple top-down game that requires the player to avoid rolling boulders that would bounce off of walls (See Figure 1), this game would feature a very simple control scheme in-which you just need to move the player.

Figure 1

Hyper Casual games are typically easy to play, and feature minimalistic user interfaces. As most of the games consist to be small they can be quickly downloaded without needing any instructions, and thus gather a wider audience of players.

“A hyper-casual game is a mobile video game which is easy-to-play, and usually free-to-play; they also feature very minimalistic user interfaces.”

wikipedia.org, 2021

Here is the progress of what I’ve made so far, there are only three objects that make the game; the player, the boulder and the walls. The player simply moves about using WASD, and the is a spherical boulder uses the walls to bounce off of and change direction.

Figure 2

In the boulder, are several overlap events where it detects if it’s hit the player or the walls. If it calls a function that hits the player then it uses a pointer to set the player’s collision to false and their death boolean to true.

If it touches a wall, it updates its direction variable to make it face a different direction. So far it only subtracts it’s current angle by 111 degrees which is currently a placeholder, to make the ball properly bounce off the wall would require some possible trigonometry.

Figure 3

What I could try to do to get some more realistic bouncing is by trying to calculate the angle of reflection from the angle of incidence once the ball hits the wall (See Figure 4).

Angle of incidence is equal to the angle of reflection
Figure 4 (oreilly.com, 2021)

How this could be done in Unreal is that I could simply get the current angle of the direction the ball is going in and to bounce it off in the opposite direction by multiplying it with a negative value to get the angle of reflection.

Hopefully I am able to improve upon this function when I next work on the project to get a more realistic feel for the boulder to bounce off of the walls.

So far I feel as if the project has gone well at least, as I’ve got the game functioning at a prototype level. The gameplay just needs more refining before I can move onto the details and possibly adding in more content.

Bibliography

En.wikipedia.org. 2021. Hyper-casual game – Wikipedia. [online] Available at: https://en.wikipedia.org/wiki/Hyper-casual_game#:~:text=A%20hyper%2Dcasual%20game%20is,feature%20very%20minimalistic%20user%20interfaces.&text=Usually%20featuring%20infinite%20looped%20mechanics,leading%20to%20their%20addictive%20nature. [Accessed 23 November 2021].

O’Reilly Online Learning. 2021. HTML5 Canvas, 2nd Edition. [online] Available at: https://www.oreilly.com/library/view/html5-canvas-2nd/9781449335847/ch05s02.html [Accessed 23 November 2021].

Categories
Uncategorised

GD2 Blog: Week 6

Particles

As of the 9th of November, I looked into adding onto my previous project with effects such as particles. This was done using one of Unreal’s VFX systems known as “Niagara”.

For my project, I just wanted to create a simple particle effect that came out of the weapon once the player fired it. Within the gun’s blueprint I attached a Niagara particle system that would play on the end of the gun (See Figure 1).

Figure 1

Before, alongside an emitter I set up a particle system. This is a container that has multiple emitters into one combined effect which I am able to modify how they act in-game – for instance I can make them go a certain direction or speed.

You can also view how it will play out within the timeline panel.

“In the Niagara System Editor, you can modify or overwrite anything in the emitters or modules that are in the system. The Timeline panel in the System Editor shows which emitters are contained in the system, and can be used to manage those emitters.”

docs.unrealengine, 2021

As shown in Figure 2, I am editing the emitter I made within the particle system.

Figure 2

Within my character’s code, I check to see if the player is shooting and then use a for loop to check for any currently active weapons that are guns. This then activates the weapon’s “Effects” function (See Figure 3).

Figure 3

This function enables a boolean which will then activate our particle system within the weapon’s blueprints.

Figure 4

Using an event tick, the game constantly checks to see if the gun is firing and then plays the effect alongside with a sound (See Figure 5).

Figure 5

Here is what the particles look like in-game once the player fires (See Figure 6).

Figure 6

This was a fairly simple task, but I enjoyed learning a different system within Unreal. It was interesting to check out the particle system and how it could be utilized within our games.

Bibliography

Docs.unrealengine.com. 2021. Niagara Overview. [online] Available at: [Accessed 16 November 2021].

Categories
Uncategorised

GD2 Blog: Week 5

Unreal and C++

As of the 2nd of November, we studied using Sockets in Unreal. For this lesson we used one of the default templates to demonstrate what sockets can do, I chose the third person template as I can use that to make a character walk over items and pick them up.

Sockets can be applied to certain bones on models which can allow for other meshes to attach themselves onto them, for example you may want to attach an item to a hand.

“Sockets can then be translated, rotated, and scaled relative to the bone. Static Meshes and/or Skeletal Meshes can also be previewed attached to sockets.”

docs.unrealengine, 2021

The first thing I did within my project was go onto the third person character’s model, and set up sockets in their right hand for two different types of weapons (See Figure 1).

Figure 1

After that, I created a pickupable item similar to previous sessions, this was simply named as “Weapon”.

However this time it has a USkeletalMeshComponent, which enables it to attach to the sockets on the player (See Figure 2).

Figure 2

Next up was to create a function within the Weapon’s cpp file pointing to the third person character, this function is activated by an overlap beginning.

Within the function, if the weapon is overlapping with the character then it will get one of the sockets from the character’s mesh, and then attach our weapon to it

The weapon that’s being picked up will also be set to one of the player’s equipped slots (See Figure 3).

Figure 3

These weapons can also be stored onto the character, within the character’s header file there are several class variables for the potentially picked up items.

Included are also functions that set the player’s current weapon and their equipped ones – these will then be able to be switched between eachother via a player input (See Figure 4).

Figure 4

Once this function is called by the weapon overlap, it will set one of the player’s EquippedWeapon variables to it. First it checks to see if the weapons actually contain variables before setting them (See Figure 5).

Figure 5

As each weapon contains a variable, it is important to know which ones are enabled. This function makes sure the current equipped weapon plays the correct animation for our player, which I have done by using booleans (See Figure 6).

Figure 6

Using an animation blueprint, I have added some new animation states to the player which can be triggered depending on their variables.

In example, the transition between the Idle/Run state to the Gun one is dependent on whether the “Has Gun?” boolean is active or not.

Figure 7

Here are the animations for the player changing depending on which weapon is currently on the right hand socket (See Figure 8).

Figure 8

The player is also able to shoot the gun, which triggers a unique shooting animation until they stop holding left click. This was simply done using the bind actions with the player inputs.

Figure 9
Figure 10

I feel as if this was a fairly tough task, however I feel like I do have a better idea of how to use sockets and how actors can work together using pointers and variables. This may be interesting to experiment with more in later sessions.

Bibliography

Docs.unrealengine.com. 2021. SkeletalMeshSockets. [online] Available at: https://docs.unrealengine.com/4.27/en-US/WorkingWithContent/Types/SkeletalMeshes/Sockets/ [Accessed 16 November 2021].

Categories
Uncategorised

GD2 Blog: Week 4

Unreal and C++

As of the 25th of October, we started a new project where we experimented more with using cameras and a different style of control for our third person character.

To set up our camera so it spawns and follows, we create it within in our character’s default values (Figure 1).

Figure 1

To make sure the camera follows our player, we use a “SpringArmComponent” which our following camera will be attached to.

We can set how long the length is, which is the distance of how far away it is from the player, we can also enable camera lag which makes the following feel smoother.

Basically what this does is help the camera remain at a certain distance from the player but also not phase through other objects.

The SpringArmComponent tries to maintain its children at a fixed distance from the parent, but will retract the children if there is a collision, and spring back when there is no collision.

docs.unrealengine (2021)

This can be useful as to not get the camera stuck behind geometry that could possible obstruct the player’s view and thus hinder gameplay.

We also added some animations by using more animation blueprints and an animation instance C++ class.

In our header file, we include some variables such as our character’s movement speed and a reference to their pawn (See Figure 2).

Figure 2

In our CPP file, we set the pawn value to our character. If the pawn hasn’t been set, then it will try to return a pointer to the owner of the animation instance within the NativeInitializeAnimation void.

In the next void where we update our animation properties where we get a speed variable from our current pawn.

The next line we create a variable called LateralSpeed which only takes the speed from the pawn’s X and Y movements and leaves the Z axis out, we then get the magnitude of the speed in the next line by returning the size of our LateralSpeed.

Figure 3

In our animation blueprint, we then connect our variable to our IdletoRun state, so that we can base which animation plays off of the speed of the player.

0 would set the animation to an idle state, more than 0 sets it into a moving state where it is walking. If the speed is greater than a certain amount then a running animation will play instead.

Figure 4

Bibliography

Docs.unrealengine.com. 2021. Camera Components. [online] Available at: https://docs.unrealengine.com/4.27/en-US/Basics/Components/Camera/ [Accessed 4 November 2021].

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

Categories
Uncategorised

Developer Journal : Prototype Gameplay

Developer Journal

I’ll be going over the gameplay of my prototype, and how each level in my Unreal Game is designed to help teach players the mechanics of the game.

Good level design is crucial for the prototype as it is a good way to introduce the the mechanics as straightforward as possible through player experience.

“Level design incorporates player capabilities, game mechanics, obstacles, and discoverable elements that create a positive user experience.”

Master Class, 2021

When making my prototype, I considered the best way to incorporate my mechanics would be to let the player discover them at their own pace once first introduced.

Many of the early levels have a fairly linear path which makes them easy to navigate, so the mechanics laid out are more obvious. In the first level the player starts directly in front of a locked door in a single room, and must find a way to a key.

The red key is accessed by a sliding block in a one-way gap that can be only pushed into one direction, the player will be lured to the left side by the glowing key and find the dark area.

After getting the key, the player should head towards the red door to get the blue key which opens the locked gate at the entrance – the idea this should convey is that each coloured key opens their counterpart doors (Figure 1).

Figure 1

After being taught the mechanics of the sliding blocks and keys, the next level further focuses on the sliding blocks and also introduces a new mechanic.

The player starts off in a one-way gap in front of a sliding block, being their only path they have no choice but to push this block. Afterwards they’ll then learn that they are able to push blocks downwards – players may also be lured to the exit and make another bridge with this new knowledge in mind (Figure 2).

Figure 2

However, once they try to form the second bridge, the block pushed off the platform reveals a pressure plate that requires a block to be pushed onto it for the door at the exit to keep open.

This means the player has failed the level, as it is impossible to get the block back up, their only option is to self-detonate as hinted under the level name (Figure 3).

Figure 3

On their second retry, the player would try to form the bridge on the lower path of the level instead to get more blocks. There’s enough blocks to form both bridges and also leave one to weight down the pressure plate (Figure 4).

Figure 4

The next level combines most of the mechanics learned from previous levels, these are formed into a much bigger scale level to further test the player’s knowledge on what they’ve learned.

This level requires the player to collect keys, slide blocks and to make use of the pressure plates to unlock their assigned doors (Figure 5).

Figure 5

The fourth level takes place in complete darkness, and requires the player to make paths around it using the sliding blocks much like the second level but much harder.

The main challenge here is to explore the level’s layout whilst making use out of the player’s passive ability: the light (Figure 6).

Figure 6

The final level of the prototype introduces the first enemy, who starts off in a square room. This is a basic representation of the enemy’s path and direction, as they move straight forward and turn 90 degrees left once they hit a wall.

If the player rushes, then they may come into contact with the enemy and initiate a chase sequence. If the player makes it to unlocking the door, there still will be a delay before it fully opens so there’s a high chance of the enemy catching up to the player by then.

The level teaches you to stay out of the enemy’s sight, and to be patient (Figure 7).

Figure 7

The game has also gone through playtesting, and much of the praise has gone towards how the levels are structured – albeit a couple of bugs as seen in Figure 8.

Figure 8

I’m glad to know that the levels I’ve designed were a success at teaching the game’s core mechanics in an engaging, and fun manner.

To improve upon this, I’d polish the current levels to iron out some bugs and also add in some new ones, though due to time constraints I can’t add more mechanics and further explore current ones as I would’ve liked to of done.

Next time, I may try to get some more play testers so that many more will be likely to uncover oversights like bugs.

Bibliography

Master Class. (2021) How to Become a Video Game Level Designer. [online] Available at: https://www.masterclass.com/articles/how-to-become-a-video-game-level-designer [Accessed 19 May 2021].

Categories
Uncategorised

Developer Journal : Unreal & Blender

Developer Journal

As I’ve mentioned creating 3D Models in some other blog posts, I’ll be going over my process in using Blender to create models and importing them over to Unreal.

For my project, I chose to use Blender as it is a free and open source program. This is mostly intended to benefit independent artists and small teams.

“We build a free and open source complete 3D creation pipeline for artists and small teams, by publicly managed projects on blender.org.”

blender.org, 2021

Because of this, I consider learning and using Blender is good opportunity to show that we can go the extra mile for our Indie Dev project and detail it more.

For my game, I want a low-poly and pixelated style. To avoid any inconsistences for when I get to texture the model, I use a grid snap function to make sure the model’s shape stays accurate to each square on the grid (See Figure 1).

Figure 1

Next up after the model is done would be setting up a UV map for unwrapping and texturing the model, a UV map is a flat representation of the model and is primarily used to wrap textures.

“A UV map is the flat representation of the surface of a 3D model used to easily wrap textures. The process of creating a UV map is called UV unwrapping.”

Thomas Denham, 2021

As you can see, the UV in Figure 2 is unwrapped into 2D shapes on the left representing each face of the model. These 2D shapes can be drawn on to form the textures for the model as shown on the right.

Figure 2

Once a model is done, I export it as an FBX and set the smoothing to “Face” – this is a type of smoothing Unreal supports when importing models and prevents errors from occurring (See Figure 3).

Figure 3

Finally, the model and texture both get imported into Unreal as an asset. To get the model to display the texture I simply open up the asset and set it a new material with the texture on it (Figure 4).

Figure 4

To make the assets stand out much better during gameplay, I edit the materials to have an Emissive Colour attached and then wire it through a multiplier. They also have their Roughness set to 0 as to give them a very glossy look to further capture the attention of the player (Figure 5).

Figure 5

In-game, this makes the objects stand out much better in the dark by using a subtle glow. The reason as to why I’ve done this for my game is to help with the readability of important objects the player will be interacting with (See Figure 6).

Figure 6

I’ve also made plenty of models for my project for detail, this goes for most of the items and environmental objects you can see.

Figure 7 shows a key I modelled to go with the doors, this is a collectable picked up by the player.

Figure 7

Figure 8 shows the sliding blocks, these are given bevelled edges to help distinguish them from the walls.

Figure 8

Figure 9 shows a cell wall, this is essentially just for detail and serves no purpose within the game.

Figure 9

Figure 10 shows a character model I created for the player, however I have not managed to import and animate this into the game due to time constraints.

Figure 10

Overall, I feel as if Blender and Unreal are great tools to work with.

I think it is important to learn different skills with different programs to better improve the versatility of my skills, as in Indie Development working individually or in a small team may require some extra legwork for things such as details – but that is not problem if you have learn how to do perform those skills independently.

I think in the future to improve upon these skills I could try and learn to animate within Blender and to import those into Unreal.

Bibliography

Blender Foundation. (2021) About — blender.org. [online] blender.org. Available at: https://www.blender.org/about/#:~:text=Blender%20is%20the%20free%20and,video%20editing%20and%20game%20creation. [Accessed 18 May 2021].

Denham, T. (2021) What is UV Mapping & Unwrapping?. [online] Concept Art Empire. Available at: https://conceptartempire.com/uv-mapping-unwrapping/#:~:text=A%20UV%20map%20is%20the,used%20in%20the%203D%20space. [Accessed 18 May 2021].

Categories
Uncategorised

Developer Journal : Enemy AI

Developer Journal

As of the 10th of May, I’ve made some more progress on my prototype. This time I’ve made made an enemy AI for the game, this was done with the use of Blackboards and Behaviour trees.

Figure 1 shows the enemy AI in-game with a patrol behaviour, this state is initiated on the start of the level and is reactivated when the enemy loses sight of the player.

Using line traces, the AI is able to find any wall it can collide with and sets a position to move to. Once it reaches it, the AI will simple turn 90 degrees left and repeat.

Figure 1

In Figure 2, Another behaviour is when the AI starts to chase the player, this initializes once the player comes into contact with the AI’s sight radius. Once they’ve reached the player, they’ll explode and result in a game over screen.

Figure 2

To start creating the AI, I needed to create special blueprint known as an AI Controller. This works similarly to the Player Controller, but is more focused on receiving inputs from the environment and game world.

Figure 3

“The job of the AIController is to observe the world around it and make decisions and react accordingly without explicit input from a human player.”

unrealengine.com, 2021

Using this, we are able to get the base for our AI. However we are able to make this AI a lot more intelligent with the use of a Behaviour Tree.

Creating an Advanced Asset, we are able to get our Behaviour Tree. With this, we are able to give our AI Controller some logic to follow.

Figure 4

“While the Behavior Tree asset is used to execute branches containing logic, to determine which branches should be executed”

unrealengine.com, 2021

Finally, we’ll need a Blackboard. This’ll contain certain variables we need to refer to in our Behaviour Tree.

Figure 5

Anything we want our AI to know about will have a Blackboard Key that we can reference.

unrealengine.com, 2021

Now that we have all we need, I now need to go into the AI_Enemy character I created and to set its AI Controller Class to the one I’ve just created (See Figure 6).

Figure 6

Inside the AI Controller, it runs our behaviour tree once the game starts (See Figure 7).

It also has an event linked to AIPerception, which is used to create a sight for our enemy that’s casted to our player.

If successfully sensed then a boolean will be activated in our Blackboard to activate a chase sequence – I’ll be able to explain this later.

Figure 7

Next up is the Behaviour Tree itself, as you can see there are two different branches from the selector; Patrol and Chase.

If the boolean used to detect the player mentioned earlier was false, then the left part of the tree will play. If the boolean was true then the right part of the tree will activate instead.

Each will lead to a sequence that will play certain tasks, starting from the left side, this is where the player gets given actions to do in a specific order that’s numbered (See Figure 8).

Figure 8

Inside both sequences, you can see that they both take the SeePlayer boolean from our Blackboard (See Figure 9).

Figure 9

Our first task in the left sequence starts with the enemy finding a wall, this is done using a LineTraceByChannel which starts at the enemy’s position and heads forwards in front of them by 1000 units.

Once the line hits a wall, it’ll take the vector of the hit location and use it as the enemy’s next location to move to (See Figure 10)

Figure 10

After the execution is finished, the next task in the sequence is played which will be a Move To. This is assigned to a vector variable from the Blackboard known as TargetLocation, this is where the location for where line hits is stored (See Figure 11).

Figure 11

After the enemy has moved to its location, the next and final task is to rotate 90 degrees to the left. Using a SetActorRotation, I am able to change the rotation of the enemy with a value.

The value gets the actor’s current rotation on the Z axis and divides it by 90, it then rounds it to the nearest integer and times it by 90 – this is done so we can get a perfect snap for the rotation as to avoid any inaccurate rotations.

90 is then simply taken away from the player’s z axis and thus turns them a perfect 90 degrees left once we put the value into the new rotation (See Figure 12).

Figure 12

Once this task is finished, the whole sequence is then repeated from the first task again until the PlayerSee boolean activates.

In our next sequence for when the PlayerSee boolean is activated, a chase sequence is initiated. The first task of this sequence is to simply get the player character’s location using our AI’s perception from earlier (See Figure 13).

Figure 13

Next up in the chase sequence would be a task that made the AI move to this location (See Figure 14).

Figure 14

This sequence will keep going until the enemy loses sight of our player, thus making the SeePlayer boolean false again.

As this was my first time trying to make AI within Unreal, I feel as if the task was a success and I was able to comprehend how to use the Blackboard and Behaviour Trees.

Although the AI is quite simple, it still may need some improving such as having to go back to it’s original location after chasing the player – this may have to be left for any extra polish I can fit into the game.

Bibliography

Docs.unrealengine.com. (2021) AIController. [online] Available at: https://docs.unrealengine.com/en-US/InteractiveExperiences/Framework/Controller/AIController/index.html [Accessed 16 May 2021].

Docs.unrealengine.com. (2021) Behavior Tree Quick Start Guide. [online] Available at: https://docs.unrealengine.com/en-US/InteractiveExperiences/ArtificialIntelligence/BehaviorTrees/BehaviorTreeQuickStart/index.html [Accessed 16 May 2021].

Docs.unrealengine.com. (2021) Behavior Trees. [online] Available at: https://docs.unrealengine.com/en-US/InteractiveExperiences/ArtificialIntelligence/BehaviorTrees/index.html [Accessed 16 May 2021].