Reader small image

You're reading from  Multiplayer Game Development with Unreal Engine 5

Product typeBook
Published inOct 2023
PublisherPackt
ISBN-139781803232874
Edition1st Edition
Right arrow
Author (1)
Marco Secchi
Marco Secchi
author image
Marco Secchi

Marco Secchi is a passionate game programming teacher located in Milan, Italy. In the past, he has been a freelance programmer focusing on game and application development, however he is now currently a lecturer and Lead Game Advisor at NABA (Nuova Accademia di Belle Arti). Marco continues to hone his programming skills in the R&D department at NABA, while also working on personal projects too, involving game development and cultural heritage.
Read more about Marco Secchi

Right arrow

Extending AI Behaviors

Enhancing an enemy character’s behavior in a multiplayer game is a great way of making it more challenging and exciting for players. It can also help create a more immersive experience, as enemies become smarter, faster, and stronger. By introducing new abilities or changing existing ones, you can make your game stand out from other similar titles on the market.

In this chapter, you will learn how to add improvements to your minion’s AI behavior – this will involve creating some sort of communication between your hero character’s stealth abilities and the undead minion sensing system. Additionally, you will learn how to make your opponents communicate and cooperate with each other, in order to give your thief a hard time.

You will also implement a health system for the AI opponents, make your character attack, and impart some damage on them. Finally, you will create some variations for the minions in order to make them less predictable...

Technical requirements

To follow the topics presented in this chapter, you should have completed the previous ones and understood their content.

Additionally, if you would prefer to begin with code from the companion repository for this book, you can download the .zip project files provided at this book’s companion project repository: https://github.com/PacktPublishing/Multiplayer-Game-Development-with-Unreal-Engine-5.

You can download the files that are up to date with the end of the last chapter by clicking the Unreal Shadows – Chapter 08 End link.

Making AI opponents more challenging

So far, your undead lackey is equipped with a (more or less) keen sense of vision, allowing it to peer into the abyss of the dungeon, scouting for unsuspecting prey. However, even the sneakiest of thieves can unexpectedly bump into a hindrance while tip-toeing through the shadows. The cunning Lichlord knows this all too well and has bestowed upon his minions the added gift of acute hearing, so not even a pin drop goes unnoticed!

In this section, you will implement a noise system based on player character movement. The game logic you will be adding is based on the following requisites:

  • The thief character will make a noise when sprinting
  • The noise level will be based on the character statistics
  • The AI minions will react when they hear a noise

So, open your IDE, as it’s time to add a new component feature to your hero!

Making some noise

In order to let your thief character make noise while it’s sprinting...

Implementing an alert system

In this section, you will work on a system that allows an AI character to alert its fellow minions once it detects a player character. At first glance, you might assume that the code logic to alert nearby AI opponents could be implemented directly inside the minion class – it’s just a matter of sending them a message, isn’t it? But there’s more to it than meets the eye, dear reader. It seems the Lichlord has bigger aspirations for communication than you had anticipated. Fear not, for he has dictated that you make use of a Gameplay Framework class that has lurked unnoticed in the shadows until this moment – the Game Mode.

As you will remember from Chapter 4, Setting Up Your First Multiplayer Environment, a Game Mode is a class that manages a game’s rules and settings – this includes tasks such as communicating with AI Actors in the level. Alerting them of a new intruder in the dungeon is definitely a feature...

Adding health to the AI

In this part of the project, you will add a health system to the minion AI to make it possible to defeat it during gameplay. You will also add a spawn system so that when the opponent is defeated, the player will be rewarded with a well-deserved prize.

To implement such features, we need to open the minion class and start doing some coding – open the US_Minion.h header, and in the private section, add these two declarations:

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="Health", meta = (AllowPrivateAccess = "true"))
float Health = 5.f;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="Pickup", meta = (AllowPrivateAccess = "true"))
TSubclassOf<class AUS_BasePickup> SpawnedPickup;

The first one is used to keep track of the enemy health, while the second one will contain the class of the item pickup that will be spawned once the minion is defeated. Both of them can be modified in a...

Adding a weapon system to the character

Your beloved character has been longing for a weapon system ever since you started implementing it. In this section, we shall finally grant its wishes and provide it the ability to wield (not-so) powerful tools of destruction. Let’s make our character stronger and more formidable by arming it with an amazing weapon!

Since our character hero is a sneaky thief who prefers to avoid direct combat with stronger and more heavily armored opponents, we will focus on a throwing dagger system.

In order to avoid adding cluttered code in the US_Character class, you’ll implement a brand-new component that will handle the weapon logic – this means that you’ll work on the following features:

  • A component that will be added to the character and handle the player input and dagger spawn logic
  • A dagger weapon that will be thrown at runtime and cause damage to the enemy opponents

As a first step, we will create...

Creating AI variations

Now that we’ve got the AI opponents all set up and ready to go for some epic battles, let’s add some more variations to AI minions and make things more interesting and engaging. If a project has been well planned, changing the behavior of an AI – even a basic one such as the one we created in this chapter – is usually just a matter of adjusting some settings!

In this section, you’ll create a new AI opponent, starting from the basic US_Minion class, and you will tweak its property in order to give it different behavior.

Creating an AI sentinel

While watching mindless minions wander around a dungeon cluelessly may cause a chuckle or two, it is certainly not enough for the Lichlord’s devious plans. He wants to be sure that each and every corner of his realm is safe and well guarded. This means you will craft some undead sentinels that will have keen senses and be more territorial.

Let’s start by creating...

Summary

In this chapter, you actively worked to improve the behavior of your enemy AIs within the level. The focus was on developing new features that make the gaming experience even more engaging and challenging for players. You actually improved the Lichlord’s minions’ sense of hearing to make them even more alert and perceptive when it comes to spotting those poor thieving heroes.

On the flip side, you also implemented a health system for the minions and added some pretty sharp (literally!) tools to the player’s arsenal that they can use to take down those nasty foes! Finally, you created some enemy variations to make the dungeon less boring and more engaging for the player.

As you can see from what you have built here, if you plan ahead, improving gameplay can be a walk in the park! By taking the time to carefully map out your strategies and implement the right features, you can make gameplay engaging and immersive for players while also achieving your...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Multiplayer Game Development with Unreal Engine 5
Published in: Oct 2023Publisher: PacktISBN-13: 9781803232874
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Marco Secchi

Marco Secchi is a passionate game programming teacher located in Milan, Italy. In the past, he has been a freelance programmer focusing on game and application development, however he is now currently a lecturer and Lead Game Advisor at NABA (Nuova Accademia di Belle Arti). Marco continues to hone his programming skills in the R&D department at NABA, while also working on personal projects too, involving game development and cultural heritage.
Read more about Marco Secchi