Book Image

Creating an RTS Game in Unity 2023

By : Bruno Cicanci
4.5 (2)
Book Image

Creating an RTS Game in Unity 2023

4.5 (2)
By: Bruno Cicanci

Overview of 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.
Table of Contents (23 chapters)
1
Part 1: Foundations of RTS Games
6
Part 2: The Combat Units
11
Part 3: The Battlefield
15
Part 4: The Gameplay

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.