Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Creating an RTS Game in Unity 2023
Creating an RTS Game in Unity 2023

Creating an RTS Game in Unity 2023: A comprehensive guide to creating your own strategy game from scratch using C#

By Bruno Cicanci
$43.99 $29.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5 (2 Ratings)
Book Oct 2023 548 pages 1st Edition
eBook
$43.99 $29.99
Print
$54.99
Subscription
$15.99 Monthly
eBook
$43.99 $29.99
Print
$54.99
Subscription
$15.99 Monthly

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon AI Assistant (beta) to help accelerate your learning
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Oct 13, 2023
Length 548 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781804613245
Vendor :
Unity Technologies
Category :
Languages :
Tools :
Table of content icon View table of contents Preview book icon Preview Book

Creating an RTS Game in Unity 2023

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
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Learn how to implement game architecture and gameplay features
  • Explore unit actions, resource management, physics simulations, and audiovisual enhancements to boost player engagement
  • Discover RTS mechanics such as implementing melee/ranged battles, unit spawning, dynamic maps, pathfinding, and more
  • Purchase of the print or Kindle book includes a free PDF eBook

Description

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.

What you will learn

Incorporate the most used design patterns, algorithms, and techniques into your game Employ the best coding practices used in the games industry Explore the basics of AI and physics to create high-quality games Build dynamic and configurable maps to enhance the player experience Solve complex problems using the industry standards for Unity and C# Create the mechanics present in classic RTS games using a modern approach Gain a deep understanding of how to create professional games using Unity

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon AI Assistant (beta) to help accelerate your learning
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Oct 13, 2023
Length 548 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781804613245
Vendor :
Unity Technologies
Category :
Languages :
Tools :

Table of Contents

23 Chapters
Preface Chevron down icon Chevron up icon
1. Part 1: Foundations of RTS Games Chevron down icon Chevron up icon
2. Chapter 1: Introducing Real-Time Strategy Games Chevron down icon Chevron up icon
3. Chapter 2: Setting Up Unity and the Dragoncraft Project Chevron down icon Chevron up icon
4. Chapter 3: Getting Started with Our Level Design Chevron down icon Chevron up icon
5. Chapter 4: Creating the User Interface and HUD Chevron down icon Chevron up icon
6. Part 2: The Combat Units Chevron down icon Chevron up icon
7. Chapter 5: Spawning an Army of Units Chevron down icon Chevron up icon
8. Chapter 6: Commanding an Army of Units Chevron down icon Chevron up icon
9. Chapter 7: Attacking and Defending Units Chevron down icon Chevron up icon
10. Chapter 8: Implementing the Pathfinder Chevron down icon Chevron up icon
11. Part 3: The Battlefield Chevron down icon Chevron up icon
12. Chapter 9: Adding Enemies Chevron down icon Chevron up icon
13. Chapter 10: Creating an AI to Attack the Player Chevron down icon Chevron up icon
14. Chapter 11: Adding Enemies to the Map Chevron down icon Chevron up icon
15. Part 4: The Gameplay Chevron down icon Chevron up icon
16. Chapter 12: Balancing the Game’s Difficulty Chevron down icon Chevron up icon
17. Chapter 13: Producing and Gathering Resources Chevron down icon Chevron up icon
18. Chapter 14: Crafting Buildings and Defense Towers Chevron down icon Chevron up icon
19. Chapter 15: Tracking Progression and Objectives Chevron down icon Chevron up icon
20. Chapter 16: Exporting and Expanding Your Game Chevron down icon Chevron up icon
21. Index Chevron down icon Chevron up icon
22. Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Filter icon Filter
Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5
(2 Ratings)
5 star 50%
4 star 50%
3 star 0%
2 star 0%
1 star 0%

Filter reviews by


Predrag Nikolik Oct 17, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Feefo Verified review Feefo image
N/A Nov 20, 2023
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Feefo Verified review Feefo image
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.