Home Game Development Creating an RTS Game in Unity 2023

Creating an RTS Game in Unity 2023

By Bruno Cicanci
ai-assist-svg-icon Book + AI Assistant
eBook + AI Assistant $43.99 $29.99
Print $54.99
Subscription $15.99 $10 p/m for three months
ai-assist-svg-icon NEW: AI Assistant (beta) Available with eBook, Print, and Subscription.
ai-assist-svg-icon NEW: AI Assistant (beta) Available with eBook, Print, and Subscription. $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime! ai-assist-svg-icon NEW: AI Assistant (beta) Available with eBook, Print, and Subscription.
What do you get with a Packt Subscription?
Gain access to our AI Assistant (beta) for an exclusive selection of 500 books, available during your subscription period. Enjoy a personalized, interactive, and narrative experience to engage with the book content on a deeper level.
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
Gain access to our AI Assistant (beta) for an exclusive selection of 500 books, available during your subscription period. Enjoy a personalized, interactive, and narrative experience to engage with the book content on a deeper level.
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Along with your eBook purchase, enjoy AI Assistant (beta) access in our online reader for a personalized, interactive reading experience.
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
ai-assist-svg-icon NEW: AI Assistant (beta) Available with eBook, Print, and Subscription. ai-assist-svg-icon NEW: AI Assistant (beta) Available with eBook, Print, and Subscription. BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime! ai-assist-svg-icon NEW: AI Assistant (beta) Available with eBook, Print, and Subscription.
eBook + AI Assistant $43.99 $29.99
Print $54.99
Subscription $15.99 $10 p/m for three months
What do you get with a Packt Subscription?
Gain access to our AI Assistant (beta) for an exclusive selection of 500 books, available during your subscription period. Enjoy a personalized, interactive, and narrative experience to engage with the book content on a deeper level.
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
Gain access to our AI Assistant (beta) for an exclusive selection of 500 books, available during your subscription period. Enjoy a personalized, interactive, and narrative experience to engage with the book content on a deeper level.
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Along with your eBook purchase, enjoy AI Assistant (beta) access in our online reader for a personalized, interactive reading experience.
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
  1. Free Chapter
    Chapter 1: Introducing Real-Time Strategy Games
About this book
Building a successful real-time strategy game is challenging, because of both the complex mechanics and the need to strike a balance between different elements, ensuring that players enjoy creating and executing strategies against the game's AI. Creating an RTS Game in Unity 2023 will teach you how to install and set up the Unity game engine, create a new 3D project, and build a level editor to make it easier to modify and add maps to a game. The RTS game will start to take shape while you learn to implement different core systems such as melee and ranged battles, unit spawners, camera controls, dynamic mapping generation, basic enemy AI, and the pathfinder algorithm. You'll also get to grips with implementing command units to perform actions, crafting and producing resources, basic physics and collision detection, and building an RTS game from scratch using C# and the latest features of the Unity game engine. By the end of this book, you’ll be able to make professional and high-quality end-to-end RTS games using the best practices and techniques from the gaming industry.
Publication date:
October 2023
Publisher
Packt
Pages
548
ISBN
9781804613245

 

Introducing Real-Time Strategy Games

Video games are highly complex graphic software, and, at the same time, an art form used to create interactive and immersive experiences. They are not easy to develop and most of them are difficult to master. Real-time strategy (RTS) games require the player to think ahead regarding each possible movement that they are going to perform, as well as what the opponent might do in response. If you then add a real-time constraint to this, you get one of the most challenging and competitive video games possible.

In this first chapter, you will be introduced to the definition of an RTS game and analyze a few classic examples of this sub-genre so that you understand what the main game mechanics and features are. This chapter will also cover the game and level design that defines the game project that is going to be developed throughout this book.

So, in this chapter, we will cover the following topics:

  • What is a real-time strategy game?
  • Understanding the game and level design of an RTS game
  • Creating a game design document
 

What is a real-time strategy game?

An RTS game, as its name suggests, is a subgenre of strategy game where the player plays in “real time” without needing to wait a turn. This becomes especially challenging when the match starts to build up and the player needs to handle multiple situations, make quick decisions regarding what units to train, what orders to give to the trained units, how to gather and produce more resources, where to explore in the map, where to search for the objective and, of course, try to figure out where the enemy is and what their next move will be.

Classic examples

Released by Blizzard in 1998, StarCraft is one of the most popular RTS games to this day and has a long history of professional players competing against each other in worldwide championships (it was also one of the very first esports). The classic StarCraft gameplay in the remastered version was released in 2017 and is still one of the benchmarks of this strategy sub-genre, as well as Warcraft III, which was released in 2002.

Even though these games can be listed as the most popular of this genre, it is no doubt that other games were the pioneers in many forms of gameplay and mechanics that we define as RTS today. Developed by Westwood Studios and released by Virgin Games in 1993, Dune II was the very first RTS game to introduce resources gathering, base and unit buildings, construction dependencies, and different factions with unique weapons – all features that are now part of any RTS game. Dune II was not the first RTS game, but it was the game that helped define this genre.

Another RTS game that should be mentioned is the Age of Empires series, started in 1997, which was a combination of Warcraft and Civilization, the latter being a turn-based strategy (TBS) game.

Modern games

The RTS games that were released in the 1990s defined the base of the genre, but many other games expanded the features, gameplay, and mechanics, creating sub-genres such as real-time tactics (RTT) and Explore, Expand, Exploit, Exterminate (4X).

Dune: Spice Wars is a great example of a modern 4X RTS game that was released in 2022 as early access on Steam. Following in the footsteps of Dune II, this game contains all the great features that are expected from this genre with modern graphics. Company of Heroes, a World War II-based game, also pushed RTS games further with real-time physics and destructible environments.

RTS games are also the foundation of the very popular multiplayer online battle arena (MOBA) that was born as a Warcraft III mod in 2003 called Defense of the Ancients (DotA). Years later, DotA 2 (2013) and League of Legends (2009) were released and defined a new strategy sub-genre.

There are so many great classic and modern RTS games that we could cover an entire book on them, but I had the difficult task of selecting a few of them to illustrate their beginnings and evolution.

Now, we are going to look at the features that most of these games share.

 

Understanding the game and level design of an RTS game

Game design is the art of creating the idea and the rules that describe what the game is and, more importantly, making it a fun and remarkable experience for the player. Level design is a specialization of game design that is responsible for level creation.

We can define most of the gameplay and mechanics of a video game by looking at the three Cs: character(s), camera(s), and control(s). In the following sections, we will see how these three aspects of a game help tighten the gameplay because they all work together and should move alongside each other.

Character

Characters in an RTS game are represented by the units that the player can use in the game, as well as the enemies that are spread across the map. Usually, the main game plot is not attributed to one character in an RTS game but rather to the collective units that the player, as the commander, can control to perform actions. The player will think about the strategy first, and then use the units as a tool to achieve what was planned.

Units can be controlled to explore the map, attack enemies, defend the settlement, collect resources, and create buildings. The characters here are not important, nor do they have a great impact on the game, but it is part of the strategy that the player built.

In a few RTS games, there are characters such as heroes or infamous bosses that have distinct personalities that can drive the story of the game. In this case, the player is still controlling nameless units, but there is a hero to fight alongside or a greater evil to be defeated.

Camera

The camera is one of the most characteristic aspects of an RTS game. Besides the ability to move around the map at will, as we are going to see in the next section, the camera usually shows the top view of the territory, and all parts that are not explored yet are covered with fog; this means that the player can see the unexplored regions of the map and send units to explore them, clearing away the fog.

It is also possible to zoom in and out on the map, which helps give a macro view of the battlefield before you take micro-decisions to attack, defend, build, produce, and gather resources. The ability to move the camera quickly using the mini-map is very important and useful in the late stages of the match where a lot of things are happening at the same time across the territory.

An RTS map usually has a starting point (the blue X) and shows the enemy base that must be conquered or destroyed (the red X). Only the player’s initial position is shown uncovered in the camera, and many other hidden objectives or resources are hidden in different locations on the map, so the player will find something interesting in any direction that they move.

Control

The player control is rather basic in an RTS game but it’s this simplicity that helps players make the best and quickest decisions. Controlling the camera is vital to decide where to go or to monitor what the enemies are doing, and with easy access using the mini-map, players can control the camera quickly. Besides the camera, the player can also control the troops by selecting one or more units and giving them a command – this command could be to gather nearby resources, attack an enemy, or just move to a position and wait idly for any enemy threat.

Selecting units or a building will display different options in the UI so that the player has all the information required to decide on the next steps. All control is usually done by using the mouse’s left and right buttons and the cursor movement on the screen. Some games were created or adapted to consoles and these controls were translated to the gamepad. The same happens for mobile RTS games and touchscreen controls, which work great since they’re very similar to mouse control.

Now that we know what an RTS game is and what kind of game and level design is involved, we need to define the game that will be developed by you throughout this book. The best way to define the scope of the project is by creating a simple game design document.

 

Creating a game design document

A game design document (GDD) is a document written by the game designer that defines the scope of the game, from the characters and story to the gameplay and mechanics used by the player. There are different approaches to elaborate a GDD, from straightforward text to dense documentation full of details and explanations. We are going to use a simple but effective method that consists of defining the bare bones of our game with enough details that will help us develop our game with all the features in mind.

In the following sections of this chapter, we are going to define the game that will be developed throughout this book: Dragoncraft.

Game outline

Dragoncraft is an RTS game where the player will defend a small village against the dragons that are scattered through the land. Before facing the mighty dragons and destroying their nests, the player needs to expand the small village by creating new buildings and training an army to both attack and defend the village. To grow the village, the player will need to gather and produce resources while defending the territory against orcs and exploring the lands beyond the village to find even more resources. It is important to create the right strategy to explore and defend before the dragons start to hunt for more food.

World

The level has a map showing land with a few forests, villages, and the dragon’s nest. Villages can contain both enemies and extra resources for the player, so it’s well worth the adventure to explore and raid them. Each level will have a map that increases the difficulty, giving the player more challenges.

When the game starts, the entire map is covered by clouds, so the player will have to send units to explore and review the map. The player must defend the village; otherwise, the enemies will kill all the units and take the resources away, making the player lose the game.

Characters

The player’s army can be trained to be bigger and stronger based on what buildings and levels the player crafted in the village. There will be two basic types of soldiers: the Footman, a melee combatant, and the Wizards, who can cast powerful spells from a safe distance:

Figure 1.1: Mini Legion Footman PBR HP Polyart by Dungeon Manson, ©2022 Unity Technologies

Figure 1.1: Mini Legion Footman PBR HP Polyart by Dungeon Manson, ©2022 Unity Technologies

The units can be generated and upgraded in the training camp using resources that the player collects. When both units are combined and used wisely, they can form a very versatile army.

Enemies and bosses

Hidden in other villages across the map, the enemies will wait for the player’s units to approach their territory. The orcs will attack the units with no mercy and, if they defeat the player’s units, they will follow the trail back to the player’s village to raid it. There are a few errant orcs that will spawn in different locations and search for the player’s village, attacking at first sight:

Figure 1.2: Mini Legion Grunt PBR HP Polyart by Dungeon Manson, ©2022 Unity Technologies

Figure 1.2: Mini Legion Grunt PBR HP Polyart by Dungeon Manson, ©2022 Unity Technologies

As the player starts to upgrade the units, the orcs will also become stronger by spawning new and improved versions. A few variables of the orcs with different colors and stats will keep the game challenging for the player.

The player’s objective is to find and kill the dragon and destroy the dragon’s nest. A few orcs will help the dragon, which is like the level boss, to defend the nest and attack the player. Each level will have a different dragon with different stats:

Figure 1.3: Dragon the Soul Eater and Dragon Boar by Dungeon Manson. ©2022 Unity Technologies

Figure 1.3: Dragon the Soul Eater and Dragon Boar by Dungeon Manson. ©2022 Unity Technologies

If the player is taking too much time to find the dragon’s nest, a new dragon will be spawned to protect the nest while the other dragon goes to look for the player on the map. The dragons are quite strong and it will take a few unit upgrades and a large army to defeat them. Unlike the orcs, the dragon will not abandon its nest to look for the player’s village if it kills all player units sent to explore the map.

Gameplay overview

Dragoncraft is an RTS game where the player starts in a small village with a couple of units and very limited resources. The player will need to expand their village by gathering resources and training more units to be prepared to find and kill the dragon hidden on the map. The player gives commands to the units to gather resources, build or upgrade a construction, and train more units.

When the game starts, only the village is visible in the top-down camera, and the player must select and command the units to go explore the map and clear the way. The mini-map on the UI is a great tool to quickly move the camera to a desired location on the territory and will be very helpful in the late game.

Enemies, controlled by the game’s AI, are hidden across the map and will attack as soon as they see the player’s unit approaching. Also, from time to time, a few enemies will start to explore the map and find the player’s village to raid and loot the resources. The player must explore and find the dragon hidden on the map, defeat it, and destroy the nest. If they take too much time to find the dragon, the dragon will start to look around and explore the map, but the nest will be very well guarded by another dragon.

The player oversees the village and gives out orders to make the units perform activities. The player mainly completes input via the mouse, in which they can do the following actions:

  • Left-click to select a unit or building
  • Left-click and drag to select units
  • When the units are selected, right-click to set a movement target (when the target is in a valid position) or attack an enemy
  • When units or a building is selected, the UI at the bottom of the screen will change to display information and extra actions available
  • Moving the mouse cursor in any direction will also move the top camera

Besides the mouse, the player can use the Escape key to pause the game, and the Space key to move the camera back to the village.

Game experience

The player must have the feeling that they need to think and act quickly as the enemies are doing the same to raid the village. All tools and resources available should be useful for the player to make decisions and see the outcome so they can plan the next steps.

The game should be balanced in such a way that a series of wrong decisions may lead the player to lose the game, but at the same time, the right decisions lead them to victory. The victory path should be challenging and not a shortcut that will make the player so strong that nothing can defeat them. In the end, the player must feel rewarded by the experience and want to play again but on a slightly more difficult map.

Mechanics and modes

The gameplay mechanics are the classic RTS actions that the player must choose wisely because each one takes some time to complete, and the units can’t be interrupted once they start an action. The selected units can perform different actions, such as the following:

  • Gather resources from a location and bring them to the main village building
  • Build or upgrade constructions
  • Attack an enemy
  • Move and stay idle in one specific spot until another command is given

There are different types of buildings and they can all be upgraded. These buildings are required to store resources, train new units, and unlock new upgrades. Besides the main hut, all other buildings must be constructed using at least one unit, and the cost of resources is displayed in the UI. The buildings are as follows:

  • Town Hall: This building is responsible for storing resources. Upgrades will increase the number of resources received and unlock other buildings.
  • Barracks: This building is responsible for the units’ training. Upgrades will unlock different units such as the Wizard for ranged combat and stronger units to be trained.
  • Defense Tower: This building is used for defense. If the enemies enter the tower area, a ranged attack will hit them.
  • Blacksmith: This building is used to craft strong weapons and armor for the units, giving them more means of attack and defense.

Once the player finds and defeats the dragon, and destroys the dragon’s nest, a new game will be offered to the player, where they can choose to play the same map again or the one that was unlocked by completing the current one. Each map is predefined, and no random levels are generated.

The GDD is a great resource for describing what the game is about and the gameplay and mechanics that make it a great game. It is also important to let the game developers know what to create and how everything connects to make a memorable experience for the player.

 

Summary

In this chapter, we learned what an RTS game is and what the main gameplay mechanics that define this genre are. We also looked at a few examples of such features that led to our own GDD, which contains the outline of the game that will be developed through this book: Dragoncraft.

In Chapter 2, Setting Up Unity and the Dragoncraft Project, we are going to download and install the Unity editor, learn how to set up Visual Studio Code to work with the engine, and how to create a new project and organize all assets that will be downloaded and used in later chapters.

 

Further reading

For more examples of RTS games and their history, check out these links:

You can learn more about game design by reading these excellent books:

  • Schell, Jesse. The Art of Game Design: A Book of Lenses. 3rd ed. (2019) CRC Press
  • Rogers, Scott. Level Up! The Guide to Great Video Game Design. 2nd ed. (2014) Wiley
  • Fullerton, Tracy. Game Design Workshop: Playcentric Approach to Creating Innovative Games. 4th ed. (2018) CRC Press
About the Author
  • Bruno Cicanci

    Bruno Cicanci is a software engineer and game developer with professional experience on different technologies and platforms. Since 2009, Bruno helped to develop and publish many games, mainly using Unity for mobile devices. He writes about game development on his personal blog, which led him to present many talks at universities and events. Bruno holds a Computer Science BS. Degree and a specialization and Game Production and Programming. In the last decade, he worked at prestigious game studios such as Glu Mobile, Electronic Arts, and Aquiris. He is currently developing games and reusable technologies at Ubisoft. Originally from Sao Paulo, Brazil, Bruno currently resides in London, UK with his wife and two adorable cats.

    Browse publications by this author
Latest Reviews (2 reviews total)
Creating an RTS Game in Unity 2023
Unlock this book and the full library FREE for 7 days
Start now