1
A Primer to the Third Dimension
Welcome!
It's a pleasure to have you join us on this journey to learn the fundamentals of 3D game development. Firstly, we will introduce you to the team who wrote this book.
- Travis Bapiste (3D Artist) directed the art, modeled every model in the game, rigged the character, and helped define the design of the story.
- Russell Craig (Sr. Software Engineer) created the scripts for the mechanics.
- Ryan Stunkel (Sound designer) created and implemented all the sounds throughout the project.
- Anthony Davis (Sr. Technical Artist) wrote the book, managed the project, built effects and shaders, and polished the project.
Ensuring we brought out the best of our collective experience of over 50 years (with 4 brains behind every page in this book) was a roller-coaster (and too much fun!) each day. We've spent over six months and two revisions to the entire book (as well as hundreds of GIFs that we have exchanged during the process) to include the most suitable use-cases that explain new concepts and, most importantly, offer a teaching approach that works. In the end, we believe we've successfully created a book that would have shaped the trajectory of our careers in game development and pushed us ahead by at least 3-5 years.
This book will equip you with all the tools you'll need to start building; however, you might need more support and advice en-route to turn your ideas into creations.
That's where our Discord server comes into play. It introduces the element of interactivity for us to connect, read the book together and have a conversation about your 3D game projects. I am available on Discord more than ever to ensure you get through with the book with ease, so please feel free to come say hi and ask any questions!
Don't forget to drop in your quick intro in the channel #introduce-yourself when you join in: https://packt.link/unity3dgamedev
Well, let's get started!
Goal of this book
Our goal with this book is to enable every reader to build the right mindset to think about 3D games, and then show them all the steps we took to create ours. An absolute beginner is welcome to work through this book, however the topics may ramp up in difficulty quite quickly. Though difficult, if you stick with it, you will have taken multiple steps towards mastery in game development. The main target audience for this book is those with some prior knowledge in game development, though regardless of your experience, we hope to create an enjoyable learning journey for you. The concepts we will cover soon become complex with characters, programming, design patterns, and more that we'll learn.
To make the best use of the book, I'd recommend you follow the approach below:
- Read through the chapters, deliberately taking breaks to think about the concepts.
- When something is brand new, check our project in GitHub to see if viewing it in action can help explain it further. If it doesn't, take to Google to do your own research on it.
- If something isn't available in the project, send me a message over Discord or seek help from peers in the community server-the link is shared above.
- Move on to the next section and repeat!
This approach will allow you to take ownership over the areas you struggle with; once you have gone through the process, you can seek help from peers. The problems that you encounter may also be encountered by others. Solving them and bringing them to the Discord or having your peers help with the solution emboldens the overall knowledge of the community.
This book is designed for you to read through our approach and then look into the project to understand all the underpinnings. It's more important to understand the design of why we did what we did first. We take time to go over fundamentals of the Unity interface as well, but tech can be learned over time with plenty of resources online.
Some things you will not find in here are how to model characters, rig, or animate them. We speak very little about this process as that is its own training. We do go over why we designed our character the way we did, to help you on your journey to do the same. The project has all the animations and cinematics in it, so the final products are available to see the results of our work. This approach is a strong way to learn, and we teach you why things are done the way that they are. This way, you get to see the end result, and you're allowed to be creative and give your own thought to design, as well as work through the process on your own with new tools while working your way through the chapters.
Lastly, before we sink our teeth into the content, we'd like to advise you to open the GitHub repo, navigate to the Builds
folder, and play it for yourself. This will help you to see what our small team put together in its complete form. After playing it through, you can visualize what we went through while building this project from the start.
Let's dive into what topics we will cover in this chapter:
- Coming around to 3D
- Essential Unity concepts
- The Unity interface
Let's get started by familiarizing ourselves with the basic components of 3D game development.
Coming around to 3D
We will be going over a basic understanding of 3D work within this section. From coordinate systems to the makeup of how the 3D model is rendered, we will only go surface-level to ensure that you fully understand the foundations as you progress through this journey. By reading through this, you will gain a strong understanding of how Unity displays items.
Coordinate systems
3D coordinate systems are not all the same in each 3D application! As is demonstrated in Figure 1.1, Unity is a left-handed world coordinate system with +y facing upward. Looking at Figure 1.1, you can visualize the difference between left-handed and right-handed systems.
Figure 1.1: Coordinate systems
While we work within these coordinate systems, you will see the positions of objects represented in an array of three values within parentheses as follows:
(0, 100, 0)
This represents (x, y, z) respectively. This is a good habit to get into as programming utilizes very similar syntax when writing positions within scripts. When we talk about position, it is commonly referred to as the transform
inside whichever Digital Content Creator (DCC) you're using. In Unity, the transform holds position, rotation, and scale.
Now we understand the world coordinates, (x, y, z), and that those coordinates each start at 0, represented by (0, 0, 0). In Figure 1.2 below, where the colored lines meet is (0, 0, 0) in the world. The cube has its own transform
, which encompasses that object's transform
, rotation, and scale. Keep in mind that transform
holds the local position, rotation, and scale. World transforms
are calculated from this following their hierarchy.
Figure 1.2: 3D coordinate system
The cube in Figure 1.2 is at (1, 1.5, 2). This is called world space as the item's transform
is being represented through the world's coordinates starting from (0, 0, 0).
Figure 1.3: World space vs local space
Now that we know the cube's transform
is in relation to the world (0, 0, 0), we will go over the parent-child relationship that describes the local space. In Figure 1.3 above, the sphere is a child of the cube. The sphere's local position is (0, 1, 0) in relation to the cube. Interestingly, if you now move the cube, the sphere will follow as it's only offset from the cube and its transforms
will remain (0, 1, 0) in relation to the cube.
Vectors
Traditionally, a vector is a unit that has more than one element with a direction. In a 3D setting, a Vector3
will look very similar to what we've worked with so far. (0, 0, 0) is a Vector3
! Vectors are used in very many solutions for game elements and logic. Usually, the developer will normalize vectors so, that way, the magnitude will always equal 1. This allows the developer to work with the data very easily as 0 is the start, 0.5 is halfway, and 1 is the end of the vector.
Cameras
Cameras are incredibly useful components! They humbly show us their perspective, which allows our players to experience what we are trying to convey to them. As you may have guessed, a camera also has a transform
, just like all GameObjects (which we will describe later in the chapter) in the hierarchy. Cameras also have several parameters that can be changed to obtain different visual effects.
Different game elements and genres use cameras in different ways. For example, the game Resident Evil uses static cameras to give a sense of tension, not knowing what's outside the window or around the corner, while Tomb Raider pulls the camera in close while the player character Lara goes through caverns, giving...