Book Image

Building an RPG with Unity 2018 - Second Edition

By : Vahé Karamian
Book Image

Building an RPG with Unity 2018 - Second Edition

By: Vahé Karamian

Overview of this book

In a role-playing game (RPG), users control a character, usually in the game's imaginary universe. Unity has become a top choice for developers looking to create these kinds of immersive RPGs. Building an RPG with Unity 2018, based on building some of the most common RPG features, teaches you tips, tricks, and techniques that can be applied to your own game. To start with, the book guides you through the fundamentals of role-playing games. You will learn the necessary aspects of building an RPG, such as structuring the game environment, customizing characters, controlling the camera, and designing other attributes such as inventory and weapons. You will also explore designing game levels by adding more features. Once you have understood the bigger picture, you will understand how to tackle the obstacles of networking in Unity and implement multiplayer mode for your RPG games. By the end of the book, you will be able to build upon the core RPG framework elements to create your own immersive games.
Table of Contents (16 chapters)
Title Page
Copyright and Credits
Packt Upsell

Characteristics of an RPG

Role-playing video games typically rely on a highly developed story and setting, which is divided into a number of quests or levels. Players typically control one or more characters by issuing commands, which are then performed by the player character based on their defined abilities and attributes. Throughout the game, these attributes increase or decrease, and set the personality of the character.

An RPG usually also has a complex and dynamic interaction mechanism, defined and developed between the player character and the world within which they are immersed. This includes interaction with the world environment, as well as other non-character players defined within the world. Due to these factors, there is usually more time allocated to designing and developing the codebase that deals with the behavior and artificial-intelligence (AI) handling such events throughout the game.

The key elements of an RPG are as follows:

  • Story and setting
  • Exploration and quests
  • Items and inventory
  • Character actions and abilities
  • Experience and levels
  • Combat
  • Interface and graphics

Story and setting

The premise of most role-playing games tasks the player with saving the world, or whichever level of society is threatened. There are often twists and turns as the story progresses, such as the surprise appearance of estranged relatives, or enemies who become friends or vice versa. The game world tends to be set in a historical, fantasy, or science fiction universe, which allows players to do things they cannot do in real life, and helps players suspend their disbelief about the rapid character growth.

As stated previously, RPGs are heavily invested in story-telling. This is one of the main key entertainment factors of the genre. Due to this fact, when you are developing your RPG, you will need to pay close attention to how you develop your story and the characters that are within your story. This, in turn, translates into the kind of environments and settings you will have for your game, and characters within the game.

Traditionally, RPGs progress the plot based on decisions that the player character makes during gameplay. This puts a great deal of pressure on the game designer, who needs to be able to integrate such forks in the gameplay with the main storyline of the game. This also raises the issue of how to program the game to take into consideration of all the different paths within the story.

To make the game more interesting and attractive, the game designer can introduce special triggers within the story to make it more interesting or challenging. This is usually done by introducing new characters and/or areas to discover within an existing level. The following is a simplified description of the storyline and the setting we will be building for our cRPG.

A glimpse of a cRPG story

Once upon a time, there was a great kingdom ruled by the great King Zazar. The ruler of the kingdom was a generous lord to his subjects. The kingdom under the rule of Zazar was peaceful and prosperous; however, over time, internal family rivalry and struggle caused cracks in the strong bond that kept the kingdom intact.

Due to mysterious events, the great king decided to move his family away from the kingdom and trust his son to one of the wise elders that he trusted. The kingdom was never the same. Until now! Expanding on our story, in the second edition, we will implement more gameplay, as well as the introduction of quests.

Exploration and quests

The whole idea behind an RPG is the ability of the player to have the freedom to explore the world in which they have been immersed. The more well defined the world is, the more interesting it will be for the player to explore and in return retain their curiosity and engagement throughout the gameplay.

This is achieved by the narrative of the story developed for the RPG. Players will be specifically given the opportunity to walk around the world and explore their surroundings in order to meet their objectives.

In an open-world RPG, the player is free to roam in the world event after they have met their objective, set by the storyline. In such cases, the player can still explore any area which is no longer needed for the continuation of the quest, but they can spend time exploring the area and maybe meet some other non-player characters that they hadn't previously met while completing their mission. But generally speaking, this is not done by the player; once they meet their objective, they are eager to move on to the next quest. Hence, the question is, how much time and effort do the game designers and developers apply to a region after the main objective has been met? The answer would be not much.

Historically, the player follows a linear sequence of quests in order to realize their goals and objectives within the game. To make the game more engaging, the developer can introduce mini-quests within the main plot of the game at that particular location, to give the player the ability to explore and gain more skills and/or abilities. Since these are not part of the main storyline, they can be triggered anytime a player enters a specific area.

For instance, assume the player has completed the main objective of the level and is ready to move on to the next objective. Now, imagine that we have created an open-world environment where the user can revisit the world anytime they choose. If the player decides to go back and explore a certain area of the world they just completed, and they happen to trigger the event to launch this mini-quest, wouldn't that be a great surprise for the player? Keep in mind that these mini-quests should not affect the main storyline, but they can be used to enhance the player experience. These types of decisions are important when you are developing your game. If they choose not to take on the challenge, you should not penalize them, except if you want to be really mean.

Quests may involve defeating one or many enemies, rescuing a non-player character, item-fetch quests, or location puzzles, such as mysteriously locked doors.

A glimpse at our exploration and quests

Our game will have a total of four quests. Each quest will have unique objectives that the player will need to complete. The design and development of each quest will be discussed throughout the book as we progress.

Here is a list of the levels we will be designing:

  • Awakening
  • The village
  • Broken forest - the horizon
  • The kingdom

The game will start by immersing the player in the environment, where our hero will be given the basic training he will need to complete his mission.

Inventory system

One of the main functions and features of an RPG is the inventory system. Throughout the game, the user will come across a vast amount of collectible items that can be used for different purposes within the game to help them progress through the journey. Therefore, RPGs needs to provide a mechanism to help the player store, retrieve, and organize the content relevant to their journey. Take a look at the following screenshot:


As the player progresses throughout their journey in an RPG, they interact with the world they are immersed in. The storyline of the game usually forces the player to interact with the surrounding world and other non-player characters. These interactions are usually in the form of some sort of an exchange. Whether this exchange is done through narration, to provide the player with a better sense of the quest, or real exchange, in terms of items, is up to the game designers and developers.

The game needs a way to keep track of all the interactions between the player character and everything and everyone else. One system that is used to keep track of these interactions is the inventory system.

During the gameplay, players usually start off as a very simple character and part of the gameplay is to elevate their character by exploring the world and collecting items that will help them increase their skills and abilities.

For instance, a player might start their journey with very basic clothes. Throughout the quest, they will either interact with a non-character player, such as a merchant who will provide them with a better set of clothes, and/or some sort of a weapon to get them started. These items will be stored and managed by the inventory system, an example of which is shown in the following screenshot:

Items will be stored and managed by the inventory system

The simplicity or complexity of the inventory system will be defined by the complexity of the game and the complexity of the characters within the game. In our game, we will be designing and developing a generic inventory system that can be applied to many different types of items.

Here are some of the items that are usually collected in a game:

  • Weapons
  • Armor
  • Clothing
  • Special objects

Some of the items are collected or discovered by world exploration, and some of the items are specifically traded throughout the game. If you are setting up a trade system in a game, then you will need to provide the mechanics for the trade. A trade usually takes place while interacting with a non-player character, usually a merchant, and it will use a special window to enable the interaction of the trade to take place.

There is usually a cost associated with any trade. In general, there is a cost associated with everything the player does within the game, and the cost usually either increases the player character's ability and/or experience or decreases it. This can get pretty complex if you dig deeply into it.

The main point to keep in mind is that everything that the player will need to collect and/or manage will be done through the inventory system. Hence, this is one of the most critical features that you will need to put effort into as a game designer and developer.

One other element that can be used to enhance the gameplay for the player, and push them to strategize their quest, is limiting the amount of items they can carry in their inventory.

For instance, in real life, a warrior will have limited ability to carry different types of weapons. Let's assume that in the real world, a warrior can carry a maximum of five different types of weapon at any given time. Now, in the game world, there might be 20 different types of weapon. Do you allow the player to carry all 20 different types when they discover them? Or are you going to limit the quantity to five?

These are the small things that make the gameplay more interesting when planned out properly. There is more to an inventory system, and we will take a look at it in more detail in later chapters.

Character attributes and actions

As with any other part of RPG development, character attributes and actions are highly defined by the storyline of the game. These actions, are performed indirectly within the game when the player commands the character to perform a specific task.

For instance, in a given RPG there will be at least a couple of character classes. The following are some sample class types:

  • Barbarians
  • Orcs
  • Magicians / Wizards
  • Zombies
  • Humans

Each character class might even have subclasses of its own, with its own uniquely defined attributes. Again, this will be tightly coupled to your storyline for your RPG.

For instance, we will have the player-character, who is technically the hero of our story and of the game. The hero is usually of a certain character class; let's assume the hero is part of the Human class.

The Human class or race, then, will have some specific characteristics that will be inherited by the player character, or any other non-player character of the same type or class.


Note: The character class and race usually determine the abilities of a character within the game, which then define the types of actions the character can perform.

The strength of a character within the game is defined by the character class it belongs to and the type of actions it can perform. The performance of a character is defined by the value of the attributes defined within the character's class and race.

For instance, if we take two different character classes and compare them side-by-side, such as a human and an orc, the orc will have far superior strength and brute force than the human. However, the human may have higher intelligence and problem-solving skills, which will out-rate the strength of the Orc if applied properly. Take a look at the following screenshot:

This is another key area where the RPG designer will have to spend a lot of time defining and specifying the specifications for the design and development of the characters within the game. The sky is the limit when it comes to designing and defining your characters, but there are some key attributes that you will need to consider for any RPG.



Most RPGs allow the player to modify their characters before the game starts, or even during game play. By default, every character class will have some default attributes, and the player is allowed to adjust the values based on some modifier. The basic fundamental features allowed for modification are the sex, class, or race of a character.

It all comes down to the budget and resources that are available to you during the production of the game. In some games, you can also introduce ethical attributes into the characteristics of the character. For instance, if you allow the ability to kill or rob innocent bystanders within the game, then the player will become less liked by the friendly non-player characters, and they may not be as friendly or helpful as needed to complete your quest. In other words, you will live by the consequences of your actions!

As a final takeaway, character classes define your character attributes and hence define your character's strengths and weaknesses. These physical attributes can be simplified into the following: dexterity and strength, which determine the performance of a character during battle!

Experience and leveling

To engage the player and to get them hooked on the game, game designer use mechanics to enhance the performance of the player-character. The progress is what is termed leveling or experience in RPGs.

Leveling and experience are a key element of any role-playing game. A good leveling or experience tree will be defined for any RPG. This allows the player to develop their avatar through game play and become functionally more powerful by gaining more skills, points, and other resources necessary to complete their quest.

The ability to acquire new weapons, armor, clothing, and/or any other game play item defined in the world, the player will need to meet some specific thresholds within the game. These thresholds can be a combination of the player's acquired experience points, financial gains, and/or combat experience. There is no right or wrong when it comes to designing any of these hierarchies and/or systems. You will need to see which one works for your specific needs and how to best apply them. Take a look at the following screenshot:

In RPGs, the progress of the character player is measured by counting some defined attributes specified by the game designer. Usually, the advancements are defined by the player completing a certain task to get experience points, and slowly, the tasks and the points rewards are increased throughout the game. The player then can use the experience points to enhance his or her avatar within the game.

Again, this is highly integrated with the story line, character classes, and/or race the player has selected. Some common ways to acquire points are by killing enemies, combating non-player characters of no importance, and performing quests that have been defined within the game.

Just like in real-life, the more you play and apply your skills, the more experienced you become. The accumulation of your experience will then allow you to acquire better weapons and/or armor to strengthen your attack or defense for the next quest. Some games might give the player 100+ points and allow the player to distribute the points across the available character attributes for their avatar. Sometimes, the game automatically applies all of the experience to a specific area, such as strength.

Gaining experience will also allow the user to unlock more features and skills to be acquired by the player during game play. This is a great way to monetize your games. In reality, most free games use this principle. They provide the basics of the world and the character for free, and they monetize the game through what are called in-game purchases, to increase either resources and/or character performance.

How is this implemented? Just like the inventory system, we need a way to keep track of the progress of the player's skills. This is usually done through a skill tree. Learning or acquiring a particular skill in the tree will unlock more powerful skills and give the player the ability to utilize the skills in the game.

Combat system

Time for battle! This is the moment every player looks forward to during their journey to kill the boss, the bad guy, or the evil warlord! Every RPG has some type of combat or battle component built into the game play. This is when the player gets to use all of their acquired skills and experience to destroy the opponent or be destroyed by the opponent, depending on how the day goes.

Historically, there were three basic types of RPG combat system. What type of combat system you choose to implement for your game will have a big impact on the game play, as well as the implementation of the game.

The three types of combat system are as follows:

  • Traditional turn-based system
  • Real-time combat
  • Real-time with pause

Historically, role-playing games used to implement turn-based combat systems. This type of combat system is as follows: only one character could act at a given time. During this time, all the other characters had to remain still. In other words, they could not take any action. This type of combat system is designed to put more emphasis on rewarding strategic planning.

The next type is the real-time with pause combat system. This type of combat system is also strictly turn-based, but with a catch. If the player waits more than a certain period of time to make a move or issue a command, the game will automatically pass on the command to the other player. This will allow the other player, that is, the enemy, to take a turn and attack the player.

In this book, we will be using a real-time combat system. Real-time combat imports features from action games and creates a hybrid action RPG game genre. Action RPG combat systems combine the RPG mechanics of role-playing with the direct, reflex-oriented, arcade-style, real-time combat systems of action games, instead of the more traditional battle systems of RPGs.


Shigeru Miyamoto is best known as the creator of many of Nintendo's most beloved characters and franchises, including Mario, Donkey Kong, The Legend of Zelda, and many others. He was also the chief designer of Nintendo's Touch! Generation console series, which includes the Nintendo DS, Wii, and 3DS.

For more information, visit

User interaction and graphics

The question arises, how do we present our game world to the player? What kind of user interface are we going to provide for our game? What kind of view are we going to allow for our game? Are we going to design our world to be viewed as a top-down camera view? Are we going to create an isometric view of the world? Or are we going to create a first-person or a third-person perspective of our world?

Answering these questions is crucial, as when you are designing your game assets you will need to understand how they will be viewed in the game world. For instance, when designing your characters and/or 3D models for the game, if you know that you will be using an isometric view, then you will approach your modeling differently than, for instance, when you are designing for a first-person or third-person camera.

In our game, we will be using a third-person camera view for the presentation of our world.

The next question would be how to provide critical information to the player in a simple and meaningful fashion. Role-playing games require the player to manage a large amount of information and frequently make use of windowed interfaces to arrange the data for the player. This is usually designed and implemented through a Heads-Up Display (HUD). Take a look at the following screenshot:

HUD is frequently used to simultaneously display several pieces of information, including the main character's health, items, and indication of game progression. You can think of the HUD as the access point for all the information the user will be required to have access to and interact with during game play.

The design of the HUD is crucial for RPG games. Typically, there are a few key data elements that you would like to continuously communicate with the player throughout the game play, which are as follows:

  • Health
  • Energy
  • Stamina
  • Active weapon
  • Active shield
  • Special items
  • Number of lives
  • Access to main menu
  • Access to inventory
  • Access to skills

Once again, the design of your HUD is derived by the type of game you are designing, as well as the type of information that will need to be available to the player during game play. Take a look at the following screenshot:

Since most RPGs collect and store large amounts of data for the player character, it is very important to create an easy-to-use, yet clean HUD.

A very important thing to remember when designing a HUD is that it should never overpower the screen or become a distraction. It usually takes a few stabs to come up with a great HUD design for your game, from initial artistic concepts, to the actual implementation and testing by gamers to get some feedback before finalizing the design and internal workings.

At the end of the day, the HUD is supposed to simplify the game play for the player, and not make it more confusing. Today, many games are moving away from traditional HUDs, leaning more towards cinematic or extremely simplistic experiences during the game play. This enables the game designer to immerse the player into the world and not to distract them with a constant, static HUD.

Making a HUD that will fit into the game play and style of your game is basic. While an element-rich HUD might be extraordinary for a few games, an oversimplified HUD can be similarly successful, or more so. Everything relies upon the player encounter you need. So when you're prepared to make the heads-up display for your next game, ensure you're outlining the HUD to upgrade the player's involvement, and never over-burden the player with data.