Creating Games With Unity Substance Painter Maya 9781003050490 - Webpdf
Creating Games With Unity Substance Painter Maya 9781003050490 - Webpdf
with Unity,
Substance
Painter, & Maya
Creating Games
with Unity,
Substance
Painter, & Maya
Models, Textures,
Animation, & Code
– Jingtian Li
To Isaiah, Anaya, and (as always) my ravishingly beautiful
and stunningly intelligent wife, Kirsten.
– Adam Watkins
To my family and colleagues. Thank you for all the support.
– Kassandra Arevalo
Dedication to my parents, Alejandra & Manuel Tovar.
– Matthew Tovar
Contents
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xv
Authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
vii
Tutorial 1.2: Modular Set Pieces . . . . . . . . . . . . 43
Grid. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Create a Base Floor . . . . . . . . . . . . . . . . . . . . . . . . 44
Conclusion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
viii
Tutorial 4.3: Creating Prefabs . . . . . . . . . . . . . . 155
A Bit about Colliders . . . . . . . . . . . . . . . . . . . . . . 156
Tutorial 4.4: A Bit of Material Adjustment . . . 159
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
ix
Hands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
Hairs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
Weapon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
Final Clean Up . . . . . . . . . . . . . . . . . . . . . . . . . . 295
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
x
Tutorial 10.2: Bind and Paint Skin
Weighting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
Painting Skin Weights. . . . . . . . . . . . . . . . . . . 392
Mirroring the Skin Weights. . . . . . . . . . . . . . 397
Copying the Skin Weights. . . . . . . . . . . . . . . 397
Tutorial 10.3: Set Up Arm Controls . . . . . . . 400
Constrains. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402
IK Arm Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . 403
Tutorial 10.4: Finger Controls . . . . . . . . . . . . 405
Tutorial 10.5: Clavicle and Body
Controls. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406
Gun Joint. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410
Final Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . 410
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410
xi
Substance Painter Output . . . . . . . . . . . . . . 450
Putting it All Together . . . . . . . . . . . . . . . . . . 451
Setting Up the Animator . . . . . . . . . . . . . . . . 454
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 464
xii
Tutorial 16.2: Firing the Gun and
Introduction to Ammo. . . . . . . . . . . . . . . . . . 582
Tutorial Conclusion . . . . . . . . . . . . . . . . . . . . . 593
Tutorial 16.3: Raycasting for Accuracy . . . 593
Problem and Solution . . . . . . . . . . . . . . . . . . 597
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 601
xiii
Health Indicator . . . . . . . . . . . . . . . . . . . . . . . . 681
Tutorial Conclusion . . . . . . . . . . . . . . . . . . . . . 685
Tutorial 19.2: Using Code to Effect UI
Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 686
Case Switches or Switch Statements. . . . . 688
Health UI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 693
Tutorial Conclusion . . . . . . . . . . . . . . . . . . . . . 695
Tutorial 19.3: Buttons and Moving
between Scenes . . . . . . . . . . . . . . . . . . . . . . . . 696
Interactive Buttons . . . . . . . . . . . . . . . . . . . . . 701
Tying Up Some Loose Ends . . . . . . . . . . . . . 705
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 708
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 733
xiv
Acknowledgments
It takes the effort and support of many people to finish
a book like this. We would like to say special thanks to
everyone who contributed to this book.
Adam Watkins
xv
Authors
Jingtian Li i s a graduate of China’s Central Academy of
Fine Arts and New York’s School of Visual Arts, where
he earned an MFA in Computer Art. He currently is an
Assistant Professor of 3D Animation & Game Design at
the University of the Incarnate Word in San Antonio, Texas.
xvii
Introduction
Making a game of their own is always the dream of many
people since they are teenagers. As new technology
emerges, that dream becomes more and more accessible
each year. There is an exponential growth of game
releases over the last decade. About 10,000 games were
released on Steam in 2019, and around 1000 games per
day were released on mobile devices.
It is the best time than ever before for anyone who wants
to dip into a game development journey. However,
making a game is never an easy task. It requires all kinds of
talents to put together a working game that has amazing
visuals, engaging gameplay, immersive audio, and an
overall well-balanced system. There are many sources you
can learn different ingredients of game development,
xix
but fewer sources explain the whole recipe. This book is
dedicated to cover the entire process of making a game,
from making assets to programming, and all the way to
package a complete game.
Who’s It For?
This book is designed for beginners who want to start
their game development journey and are unsure where
to start and which direction to go. As the reader, you are
going to jump into a well-organized learning track that
guides you through all aspects of game development.
It also shields you from noises and focuses on the
fundamentals, which gives you a solid foundation and
able to branch out to nitty-gritty details without losing
the whole picture.
Environment Modeling
Environment modeling is the process of making 3D
models for environments. We are going to cover what is a
3D model, how to make them, and how to optimize them
for your game.
Character Modeling
Character modeling is the process of making 3D
characters. We will cover how to approach organic shapes
with additional modeling methods.
xx
UV Mapping
We are going to learn how to create a 2D coordinate of a
3D model to map textures to the model. The process is
called UV Mapping.
Texturing
Texturing is the process of defining the color and all other
aspects of the appearance of the model.
Rigging
Rigging is a technical skill to add skeleton and controllers
to animate the character.
Character Animation
We are going to cover the techniques and theories to
animate characters.
Game Programming
We are going to cover programming languages, theory,
and practices to create gameplay.
Final Notes
It is critical to point out that game development is
time-consuming. Please dedicate your energy and time
to the learning process, and don’t easily give up on any
xxi
obstacles. With the internet at your fingertip, you can find
solutions for just about anything.
The chapters are built so that the reader can jump into this
book where they would like. Don’t care about modeling?
Don’t do those chapters. Never want to code? Definitely
steer clear of those. Notice that all the chapters will
reference support files that can be downloaded to assist
your work in the chapters. In many cases, just grab the
support files from the chapter preceding the one you’re
about to start, and that’s the perfect place to start the
chapter at.
xxii
CHAPTER 1
Maya Modeling
Basics of Navigation
Autodesk Maya will be our tool of choice for modeling.
It is not the best modeling tool on the market, but it is the
most used over the entire production pipeline, especially
1
Creating Games with Unity, Substance Painter, & Maya
FIGURE 1.1 Maya’s user interface. The origin is the area at the center of the grid.
Rendering
The shape is drawn by the Graphic API, but the lighting is
calculated by the Fragment Shader written by the game
engine programmer. It is a complicated process, and we
do not have to understand the details and math behind it.
It is enough to know that the renderer is the tool drawing
2
Maya Modeling
What is a 3D Model?
In the menus, go to Create->Polygon Primitives->Plane.
This will create a shape in the middle of the viewport.
On the right side of the UI, look for the Channel Box.
This is a brief list of essential attributes we can tweak
for the object. Under the INPUTS section, click on the
polyPlane1 to open it and change the Subdivisions Width
and Subdivisions Height to 1 to make the plane only one
polygon (sometimes called a “face”).
Translation
On the right side of the UI, there is a column of
manipulation tools. You can try and use the Q, W, E, and
R buttons to switch between these tools: Q for the select
tool, W for the move tool, E for the rotation tool, R for the
scale tool.
3
Creating Games with Unity, Substance Painter, & Maya
To scale the model, hit the R button, and drag the various
boxes to scale it along their respective axes. You can also
drag the various squares to scale it along two axes at the
same time; you can even drag the yellow box in the middle
to scale it up along all axes, essentially making it bigger.
Anatomy of a Model
Edge
Hold down the right mouse button on the model, and you
will see a pop-up menu we call a Marking Menu. Here, we
can see various parts of the form we can switch to. With
the marking menu active, slide up and chose Edge; the
four edges around the face now appear to be in a lighter
blue color. You can click on any of the edges to select
them. When an edge is selected, it will be highlighted
with orange color. Once selected, you can change to the
Move tool (hit W on the keyboard) and drag the three
arrows to move the edge along the respective direction.
Vertex
You can also hold the right mouse button again and chose
Vertex. Four purple points will show up on the corner of
this face. These are the vertices where edges meet. You
can click to select any of them and move them around just
like how you can move an edge.
Face
Hold down the right mouse button again and chose Face;
you can now select the face and move it around as well.
4
Maya Modeling
Object Mode
Hold down the right mouse button again. This time, we
chose Object Mode. This will allow us to move the model
altogether. Object, Vertex, Edge, and Face are the primary
modes we keep switching between while making a
model.
Normal
Use the alt-left, -middle, and/or -right mouse drag to
rotate your camera to look at the bottom of the face.
You can see it appears to be black. Any face in 3D has
a front side and a back side. The front side will appear
normal, while the back side will be black or invisible
(depending on the rendering engine). Maya makes the
back of the face black in the default setting. To view
this, using the top menus find Display->Polygons->Face
Normals.
Modeling Rules
Before we start modeling anything, let’s talk about a few
important rules when modeling for games.
5
Creating Games with Unity, Substance Painter, & Maya
Polycount
Each of those four-sided faces we looked at earlier
can be triangulated into two triangular polygons. We
typically use the number of triangles of a model as the
number for polycount, even we use quads to make
a model. The reason we use the number of triangles
instead of quads is because a triangle is guaranteed
to be a flat surface, while this is not guaranteed for a
geometric figure with more than three vertices. Thus,
the rendering process uses triangles as the basic
rendering unit. Fewer polygons means your game is
easier to run (less data); so find the balance of including
the needed number of polygons to describe a shape,
but not extras.
Topology
Topology is how the faces are laid out on the model.
Use quads if possible, because quads have a strong
sense of directionality and are easy to represent shape
evolution and deformation. We want the flow of the
quads to represent the change of the surface. Figure 1.3
shows how topology is critical for deforming a face. The
loops of faces around the orbicularis muscle, nasolabial
fold, and orbicularis oris create an essential structure
to support the facial expression. Long story short,
topology is for the purpose of better representing the
shape of the model and supporting the deformation for
animation.
6
Maya Modeling
FIGURE 1.3 Effective topology (the flow of polygons) is critical to support the
deformation that will come later in animation.
Basics of Modeling
We will jump into modeling right away and introduce
various tools along the way. Keep in mind that the only way
to improve is to practice; there is no shortcut to get better.
7
Creating Games with Unity, Substance Painter, & Maya
FIGURE 1.4 The Channel Box is at the top right of the Maya UI and allows you to
change the position, rotation, and scale of a selected object.
8
Maya Modeling
FIGURE 1.5 Adjusting the size of a cube (box) via the Channel Box.
9
Creating Games with Unity, Substance Painter, & Maya
FIGURE 1.7 Using the bevel tool to round the edges of our cube.
10
Maya Modeling
FIGURE 1.9 Using the Extrude tool to create an opening at the front of the camera.
11
Creating Games with Unity, Substance Painter, & Maya
FIGURE 1.10 Added edge loops on either side of the camera chassis.
12
Maya Modeling
FIGURE 1.12 Using Vertex mode and symmetry to adjust the opening to create a
round opening.
FIGURE 1.13 Using the Extrude tool (Shift-drag) to create polygons for the inside
of the form.
13
Creating Games with Unity, Substance Painter, & Maya
14
Maya Modeling
FIGURE 1.14 Using the Extrude, Move, and Scale tools to create the front rim of
the lens.
FIGURE 1.15 Beveling and softening the edges to create the rim of the front lens.
15
Creating Games with Unity, Substance Painter, & Maya
FIGURE 1.16 Finishing off the lens by adding curvature to the glass portion.
16
Maya Modeling
FIGURE 1.17 The Input stack of the Channel Box. This shows the History of steps
created thus far.
17
Creating Games with Unity, Substance Painter, & Maya
FIGURE 1.19 Try and follow this visual guide to tweak the shape to match the
research.
18
Maya Modeling
FIGURE 1.20 Creating an upper shell hole, and finally isolating just the shell.
FIGURE 1.21 Creating the back arm by creating a simple cube, adding new edge
loops, and tweaking those to create the desired shape.
19
Creating Games with Unity, Substance Painter, & Maya
FIGURE 1.22 Using Booleans (Union) to merge two shapes together into one.
Why?
Notice that we had to end up with some triangles, and this
is totally fine; otherwise, we need to add new edge loops
20
Maya Modeling
FIGURE 1.23 Using the Multi Cut tool to create new edges to rebuild the N-Gon into
three- or four-sided polygons.
21
Creating Games with Unity, Substance Painter, & Maya
FIGURE 1.24 The Modeling Toolkit can provide faster ways to work with advanced
modeling tools.
22
Maya Modeling
FIGURE 1.25 Using the same techniques covered above to create the base of the
camera.
FIGURE 1.26 Adding new faces and edges to round off the bottom of the base.
23
Creating Games with Unity, Substance Painter, & Maya
FIGURE 1.27 Creating the bottom arm and cleaning up the topology to eliminate N-Gons.
FIGURE 1.28 Building out the bottom of the arm using a few new tricks in each
tool’s options.
24
Maya Modeling
FIGURE 1.29 Creating the notch of the arm by deleting faces, extruding edges, and bridging.
25
Creating Games with Unity, Substance Painter, & Maya
FIGURE 1.30 Our previous steps have created a form with holes in the mesh.
FIGURE 1.31 Scaling the faces of the back of the camera to fit the mounting base.
26
Maya Modeling
FIGURE 1.32 Roughing out the switch at the top using a cylinder.
Why?
We made the Subdivision Axis smaller to lower the
polycount of the little top switch. It is such a small part
that we do not need the same number of loops as the
lens. In games, polycount is important, and trimming
away those we don’t need as we work will generate
cumulative benefits in the long run.
27
Creating Games with Unity, Substance Painter, & Maya
28
Maya Modeling
29
Creating Games with Unity, Substance Painter, & Maya
Why?
You may wonder what this Freezes Transformation does.
Well, in Maya, a model has two primary components:
transform and shape. Transform governs where the model
is, how it is tilted, and how it is scaled; these are reflected
in the translate, rotate, and scale values in the Channel
Box. Shape governs the vertices, faces, and edges and
how they are combined together to form the shape of the
model; the final appearance of the model is the shape of
the model moved, rotated, and scaled by the transform
of the model. If you do recall, we have scaled the outer
shell of the camera, and that scale value will appear in
the Channel Box; freeze transform will clean that up and
bake the scale we did to the transform of the model to
the shape of the model. Many processes later (Rigging,
UV Mapping) do require the transform of the model
to be baked to the shape of the model through Freeze
Transformation so that the final look of the model is the
actual shape instead of a shape getting scaled, rotated,
and moved by a transform.
30
Maya Modeling
31
Creating Games with Unity, Substance Painter, & Maya
32
Maya Modeling
Extract Faces
With the top four rows of faces selected, hold down
Shift + right mouse button, and choose Extract Faces. Drag
the blue arrow to shift the face away; you can now see
how Maya separated the model into two objects. Notice
that in the outliner, you can see the pSphere1 becomes
a group, and there are two objects inside of it. That
transform1 is the remaining construction history that you
can use Delete History to get rid of.
FIGURE 1.36 In order to bridge collections of polygons like this, you first must
ensure that the polygons are parts of the same single object.
33
Creating Games with Unity, Substance Painter, & Maya
After creating the curve, you can still edit it by holding the
right mouse button on it and choosing Control Vertex.
Then you can move the CV to refine the shape as desired.
The curve will be created on the grid by default. You can
go to the front, top, or side view to create your curve
FIGURE 1.37 Using the CV Curve Tool to create a series of CVs that define a curve.
34
Maya Modeling
35
Creating Games with Unity, Substance Painter, & Maya
FIGURE 1.39 Once a NURBS form is created, the form can be adjusted by editing the
curves used to create it.
Until now, you can still tweak the curves to change the
radius and the shape of the curve. When you are happy
with the form, select the polygonal shape and delete
the history and delete all curves and the original NURBS
surface as they’re no longer needed.
36
Maya Modeling
37
Creating Games with Unity, Substance Painter, & Maya
FIGURE 1.42 Tweaking the Extrude along curve options to get the resolution you desire.
Duplicate, Duplicate
with Transform
You can grab any model and press Ctrl + D to duplicate it.
The duplicated model will be at the same location as the
original (although you’ll see the name of the new form
in the Outliner). Right after duplicating, you can use the
Move tool to move the new duplicate away (Figure 1.43).
38
Maya Modeling
Duplicate Special
From time to time, we may want to create multiple
duplications but as instances. An instance is a copy that
keeps the link of the shapes between the original and the
copy; we can adjust any one of the duplications to update
the shape of all others (but not transform). Grab your
model and go to Edit->Duplicate Special□. Change the
Geometry type to “Instance”. Change the first number of
the Translate to 2 (the X axis), and the Number of copies to
“10”. Finally, press the Duplicate Special button, and you
will see ten duplications of your model, each two units
away from each other, and more importantly, editing any
one of them will affect all others (Figure 1.45).
Mirror
Anytime you forget to have symmetry on and want
to make the model symmetrical again, you can select
the model in Object mode and do a Mesh->Mirror. Try
different axes and directions to make sure you got the
correct side mirrored. The merge threshold should be
as low as 0.001 if you wish to only have the vertex in the
center mirrored. You can also change the Border setting
39
Creating Games with Unity, Substance Painter, & Maya
FIGURE 1.45 Using instances (as opposed to copies) to make copies of an object that will change when the original is
manipulated.
Center Pivot
You can grab any model in Object mode and do a
Modify->Center Pivot; this will move the pivot of the
model to the center of its bounding box. The Pivot is the
location where the object is rotating around. It is needed
whenever you want to be able to rotate or scale a model
from its geometrical center.
Change Pivot
In any mode, you can hold down the D button on the
keyboard and drag the gizmo to adjust the location
or orientation of your pivot; you can also click on any
elements on the model to snap your pivot to that element.
40
Maya Modeling
Snapping
When moving an object or its various elements, you can
hold down the X button to snap to the grid and V button
to snap to vertices. The snapping toggles are on the Status
line, which is the row of buttons under the main menu.
The snap toggles are the six buttons with a magnet in
their icon. Try these toggles and see what they do.
Hide Model
You can grab any model or its other elements and press
Ctrl + H to hide them. To unhide, press Ctrl + Shift + H; this
will only unhide the object you are selecting (probably in
the Outliner) if you have something selected. It will unhide
everything if you have nothing selected. After making a
model, name it properly, freeze transformation, and hide
it so you can move on to the next one without the other
models blocking your view.
View Control
At any time, if your cursor is in the Viewport, you can press
the spacebar to go to the Four View layout, and this will
show you the Top, Perspective, Front, and Side views;
you can then move the cursor to any view, and press the
spacebar to maximize that view. However, we recommend
to just hold down space and drag up, down, left, and right
to go to these views.
Assignments
We have covered enough commands that you are
now able to create models of your own; go ahead and
start modeling some of your own models in Maya,
41
Creating Games with Unity, Substance Painter, & Maya
FIGURE 1.46 A selection of props that can be built using the techniques covered in
this chapter.
and make sure you find references and get the correct
measurement. Figure 1.46 shows a few examples of what
we are looking for.
Geometry Errors
Sometimes in the modeling process, some errors can
emerge. These errors might not even be readily visible in
your model, but without fixing them, you can run into some
serious problems later in a game engine. While these can
be pretty technical, and the hard-core specifics are a bit
outside the scope of this book, it’s worthwhile to talk about
them for a minute and – more importantly – evaluate how
to fix them. Here are some typical geometry errors that we
can now check on your model:
42
Maya Modeling
There are two size systems we can use: decimal and binary.
For decimal, we will have sizes like 10, 20, 30, 50,
100…
For binary, we will have sizes like 16, 32, 64, 128,
256, 512… (both in cm)
43
Creating Games with Unity, Substance Painter, & Maya
FIGURE 1.47 Setting up our grid to build modularly. The person acts as a size and scale reference.
Grid
Go to Display->Grid□. Set the Length and width to 256,
and set the Grid lines to 64 and Subdivisions to 4. Drag
the slider of Grid lines and numbers to make it a blue color
and press Apply and Close. This will create a grid that has
its edge 256 cm away from the center and a blue grid line
every 64 cm with four extra divisions in-between every
blue grid line, which makes every grid 16 cm long.
44
Maya Modeling
FIGURE 1.48 Creating and snapping the first-floor module to our grid.
Why?
We want the model to be easily snapped together.
Positioning the pivot to the corner of the box is extremely
helpful for the snapping. We also want the pivot to be at
the center of the world to avoid any offset.
45
Creating Games with Unity, Substance Painter, & Maya
FIGURE 1.49 Creating the base trim of the module using Extrude.
46
Maya Modeling
FIGURE 1.52 Creating the arched top of the wall by combining a pipe segment.
47
Creating Games with Unity, Substance Painter, & Maya
48
Maya Modeling
49
Creating Games with Unity, Substance Painter, & Maya
50
Maya Modeling
FIGURE 1.57 Building the stairs. Note that for modularity to work, the exact
positions of the snapped vertices are important.
51
Creating Games with Unity, Substance Painter, & Maya
52
Maya Modeling
53
Creating Games with Unity, Substance Painter, & Maya
Step 14: Hero assets. Hero assets are the assets that
we only use a few times and so might need a
bit of extra care and detail. We will create two
hero assets for the final scene; the creation
process of these hero assets is tedious, expect
to spend a lot of time on them and have a
higher polycount on these assets. But even
though the fidelity might be higher for these
assets, the tools and commands used to create
them are no more than what we have covered
(Figure 1.66).
54
Maya Modeling
Conclusion
We have finished the environment modeling part of
our games. Well, of course, we’ve only created the
individualized separated pieces; currently they aren’t
a level...yet. However, we will move them to the game
engine and assemble them into our awesome level later.
However, before we do that, we still need to go through
UV mapping and Texturing so that our models are not
white ghosts.
55
CHAPTER 2
Maya Set UV
The UV Editor
Go to the Workspace at the top right corner of the UI, and
in the drop-down list, choose UV Editing; the viewport
now splits into two windows. The UV Editor on the right is
57
Creating Games with Unity, Substance Painter, & Maya
the place we edit our UVs. You can hold down Alt + middle
mouse button to pan the view and Alt + right mouse
button to zoom in or out. On the right of that window,
we can also see a UV Toolkit panel, which contains many
useful tools and commands to edit UV.
Select our floor piece; inside the UV Editor, you can see a
blue shell that looks like an inverted T, this is the default
UV of a cube. If you do recall, we started with a cube (if it
is not blue, move the cursor to the UV Editor and press the
number 5 button). Click on the checker icon at the row of
buttons on top of the UI in the UV Editor. You can now see
a checker texture getting displayed in both the UV Editor
and on our model in the viewport (Figure 2.2).
Select the top face of the floor, and you can see how a
face in the UV Editor is also highlighted. That face in the
UV Editor is the UV of the top face of our 3D model. Go to
the UV editor, press W to switch to move tool, and move
this face in the UV editor to the U letter on the checker
texture. You should also see the U letter appearing on the
3D model (Figure 2.3).
This face-to-face match is how UV works. UV is a 2D
representation of the 3D model; it defines how an image
can be mapped to the surface of the model. UV is also like
a flattened shell of the 3D model if you will. This checker is
a convenient way to preview how our UV maps texture on
our model.
58
Maya Set UV
FIGURE 2.3 Make the letter U appear on the model by moving the UV.
UV Points
Other than edge, face, and vertex, there is a fourth
element called UV points. These UV points are a reference
to a vertex in 3D in the UV space, and they are the building
blocks of the UV of the model. Go to the UV Editor, hold
down the right mouse button, and chose UV. You can
now select UV points, and you can move, scale, and
rotate them around just like vertices in the UV Editor.
59
Creating Games with Unity, Substance Painter, & Maya
FIGURE 2.4 Scale the UV down to make the letter U look bigger than before.
UV Tiles
The checker texture has U1V1 1001 written on it, and
this is the UV tile name. Pan the UV editor up, and you
can see U1V2 1011 above U1V1 1001. This U1V2 1011
square area is just another UV tile. Hold down the right
mouse button in the UV Editor and chose UV; drag a big
selection box to select all the UV points. Press the W
button to switch to the Move tool, and drag the UVs to the
positive, X direction. You can see now Maya places more
checker textures to the tiles your UV is overlapping with
(Figure 2.5).
FIGURE 2.5 Maya places more checker textures to the tiles your UV is overlapping.
60
Maya Set UV
FIGURE 2.6 Maya shows only U1V1 1001 if all UVs are inside of the U1V1 tile.
61
Creating Games with Unity, Substance Painter, & Maya
FIGURE 2.7 Cutting edges of the UV detach the face from the rest of the UV.
Cut UV
Select all the edges of the top face and go to the UV
Editor. Hold down Shift + right mouse button (Remember
that in the previous chapter, we talked about how this
short cut will bring up the commands suited for the
elements we are selecting), and chose Cut. You can now
see these edges appearing thicker; switch to face mode
and select the top face. Move the face around in the UV
Editor. You can see how it is detached from the rest of the
UV. You can now move it freely without affecting the UVs
of other faces (Figure 2.7).
The Problem
Looking at the checker texture mapped to our model,
you can immediately see the outer frame of our model
has a super-stretched texture. This stretching effect is due
to the UV of these faces not being laid out correctly. We
want all UVs of all faces to be flattened with the correct
proportion and not overlapping with each other. We often
don’t rely on the default UV. Now, let’s start creating the
UV of our floor from scratch.
62
Maya Set UV
UV the Floor
Step 1: Project the UV. Select the floor piece in object
mode, and freeze its transformation. Navigate
the viewport so we are looking at the model at a
non-straight angle. Go to UV->Planar□. In the
pop-up Planar Mapping Options window, go
to the Project from section, and chose Camera.
Check on keep image width/height ratio and hit
the Project button. You can now see a projected
figure of our model in the UV Editor. This planar
projection projects our model form our viewing
angle in 3D to UVs in the UV Editor, or to the UV
space (Figure 2.8).
Step 2: Cut the UV Open. The projection will only
project the model but will not be making a cut.
Imagine you got a box package delivered to you.
Without cutting the plastic tape open, there is
no way you can flatten it to a 2D surface without
faces overlapping each other. Let’s check off the
checker texture, so it is easier to see the edges.
Select all the edges of the bottom face,
go to the UV Editor, hold down Shift + right
mouse button, and chose Cut to cut them
63
Creating Games with Unity, Substance Painter, & Maya
64
Maya Set UV
Step 5: Layout the UV. Grab all the UVs, hold down
the Shift and right mouse button, and chose
Layout->Layout UV. The UV shells are now
automatically rearranged into the U1V1 space.
There is a small problem with this default
behavior: there is no gap between the UV shells;
there is also no gap between the edge of the
U1V1 tile and the UV shells.
Many texture software bleed the color
out of the UV shell a little to avoid the seam
reading the background. Go to the Layout
command again, but this time, click on the
box icon of the command to pull out the
Layout UVs Options window. Under the
Layout Settings, change the Shell Padding
and Tile padding to 10. This setting ensures
that all UV shells are at least 10 pixels away
from each other, and it also ensures they are
10 units away from the edge of the UV tile.
Press the Layout UVs button, and you can see
the difference this time in Figure 2.12.
65
Creating Games with Unity, Substance Painter, & Maya
FIGURE 2.12 Add shell padding and tile padding in the layout settings.
All digital pictures are put together this way. When we are
talking about the resolution of a computer screen, like a
4K monitor, the 4K means there are around 4000 pixels
across its width. The exact number of pixels a 4K screen
has is 3840 pixels on its width and 2160 pixels on its
height.
66
Maya Set UV
67
Creating Games with Unity, Substance Painter, & Maya
FIGURE 2.15 Cut the edges using 3D Cut and Sew UV tool.
68
Maya Set UV
69
Creating Games with Unity, Substance Painter, & Maya
Why?
We put all the UVs of all security camera models in one UV
tile. By doing so, we can create one texture for the entire
camera and save performance for our game. It is essential
to pack UVs together in a uniform and organized way.
70
Maya Set UV
Texel Density
Now we have two models UV mapped, so let’s talk about
texel density. Grab all your UVs of the camera, and go to
the UV Toolkit. At the bottom of the Transform section,
you will see a Texel Density (px/unit) part. Click on the
Get button and you can see a value calculated; in our
particular case, it is 3.1016. This value means there are 3.1
pixels per unit (cm) if you are using a texture of 512 × 512
71
Creating Games with Unity, Substance Painter, & Maya
72
Maya Set UV
73
Creating Games with Unity, Substance Painter, & Maya
Why?
We packed all of our floors into one UV shell and used a
4k (4096 × 4096) texture for them with a resulting texel
density of 4.2146 pixels per unit. Packing similar assets is a
common practice; we pack models together to have a big
texture for all of them, and this kind of texture is called an
atlas. By using atlases, we are reducing draw calls from the
game engine. 4K, of course, is a bigger texture and takes
longer to load and needs more space in the memory.
However, in many cases, the bottleneck is not how much
memory is used, but rather how often you are reading and
freeing memories. The standard may also vary from studio
to studio; consult with your technical guides to determine
the best practice for your platform and engine.
UV the Pod
One of the props we did for the environment was the pod
(Figure 2.22).
74
Maya Set UV
75
Creating Games with Unity, Substance Painter, & Maya
FIGURE 2.24 UV the monitor of the console by using the Created UV shell
command.
76
Maya Set UV
77
Creating Games with Unity, Substance Painter, & Maya
78
Maya Set UV
79
Creating Games with Unity, Substance Painter, & Maya
80
Maya Set UV
FIGURE 2.31 All the UVs and texel densities for the rest of the models.
FIGURE 2.32 All the UVs and texel densities for the rest of the models.
FIGURE 2.33 All the UVs and texel densities for the rest of the models.
81
Creating Games with Unity, Substance Painter, & Maya
FIGURE 2.34 All the UVs and texel densities for the rest of the models.
FIGURE 2.35 All the UVs and texel densities for the rest of the models.
FIGURE 2.36 All the UVs and texel densities for the rest of the models.
82
Maya Set UV
FIGURE 2.37 All the UVs and texel densities for the rest of the models.
FIGURE 2.38 All the UVs and texel densities for the rest of the models.
FIGURE 2.39 All the UVs and texel densities for the rest of the models.
83
Creating Games with Unity, Substance Painter, & Maya
FIGURE 2.40 All the UVs and texel densities for the rest of the models.
FIGURE 2.41 All the UVs and texel densities for the rest of the models.
FIGURE 2.42 All the UVs and texel densities for the rest of the models.
84
Maya Set UV
FIGURE 2.43 All the UVs and texel densities for the rest of the models.
FIGURE 2.44 All the UVs and texel densities for the rest of the models.
FIGURE 2.45 All the UVs and texel densities for the rest of the models.
85
Creating Games with Unity, Substance Painter, & Maya
FIGURE 2.46 All the UVs and texel densities for the rest of the models.
FIGURE 2.47 All the UVs and texel densities for the rest of the models.
FIGURE 2.48 All the UVs and texel densities for the rest of the models.
86
Maya Set UV
FIGURE 2.49 All the UVs and texel densities for the rest of the models.
FIGURE 2.50 All the UVs and texel densities for the rest of the models.
FIGURE 2.51 All the UVs and texel densities for the rest of the models.
87
Creating Games with Unity, Substance Painter, & Maya
FIGURE 2.52 All the UVs and texel densities for the rest of the models.
FIGURE 2.53 All the UVs and texel densities for the rest of the models.
FIGURE 2.54 All the UVs and texel densities for the rest of the models.
88
Maya Set UV
FIGURE 2.55 All the UVs and texel densities for the rest of the models.
FIGURE 2.56 All the UVs and texel densities for the rest of the models.
Conclusion
The UV part of the model may not appear on the surface
of the artwork. However, it is the foundation of the texture
of the model and cannot be overlooked. There is an
automatic UV command under UV->Automatic; it is wishful
thinking that automatic UV can get you to a decent stage.
Please don’t use it unless you have a good reason. Based
on the previous experience of teaching UV, the author
already regrets mentioning this command. The students
always think automatic UVs are fine – they are not.
Once UVs are done, the fun task of texturing starts. Let’s
jump into that in the next chapter.
89
CHAPTER 3
Set Texturing
91
Creating Games with Unity, Substance Painter, & Maya
PBR
In the modern workflow, texturing has to define all
aspects of a material, like the color, roughness, and
metalness. In the game industry, we use a standard called
PBR to define a material. PBR stands for Physically-Based
Rendering. It enforces the result of the rendering to
be physically correct by limiting the number of inputs
allowed to be adjusted. Other related material properties
are calculated internally to ensure that the energy from
the light is reflected, refracted, and absorbed by the
surface of the model based on the laws of physics. For
example, if you know the color and roughness of a metal
surface, you can already calculate the brightness and
color of the reflection using the laws of physics. There
are variants of this standard, but the most popular one
is called PBR – Metallic Roughness, and it is composed of
five surface attributes:
Base Color
Height
Roughness
Metallic
Normal
92
Set Texturing
Baking
Texturing often requires another process called baking.
Baking is a process that generates textures that contain
different information about the geometry; they are as
follows:
93
Creating Games with Unity, Substance Painter, & Maya
Why?
So far, we have been modeling with Maya with one single
file. It is because model files are relatively small, and so
managing them in one file is tidy and straightforward.
Another reason to have our models in one file is due to the
scale of our game being small enough. At some point, we
have to have more files for different models, characters,
and rigs. When we are creating more and more assets
and files, it is going to be harder and harder to trace stuff,
so we need to have a way to manage our files. Step 1
creates a folder structure that contains subfolders for us to
manage our files; we won’t need most of them. However,
since we are doing textures, the sourceimages folder it
creates is where we put our texturing file.
94
Set Texturing
Why?
What about the other models you may ask. Well, texturing
files are, unfortunately, super big, and the performance is
slow when there are so many models. We need to break
our models into multiple texturing files.
95
Creating Games with Unity, Substance Painter, & Maya
Why?
You may think, wait a minute, don’t we require some of
the models to have 4096 × 4096 (4k) textures? The answer
is yes, but 4k is a heavy texture resolution for computers
to handle. One of the superpowers of Substance Painter is
the ability to upscale the resolution at any stage without
losing any detail. It achieves that by remembering every
stroke you did while painting your texture and upgrades
them to 4k.
96
Set Texturing
Navigation
The navigation of the 3D viewport is the same as in Maya;
the navigation of the 2D viewport is the same as Maya’s UV
editor. You can press F2 to show only the 3D viewport, press
F3 to show only the 2D viewport, or press F1 to show both.
Light Direction
To change the direction of the light, hold down Shift, click
and drag the right mouse button.
97
Creating Games with Unity, Substance Painter, & Maya
Ambient Occlusion
Ambient Occlusion is a natural phenomenon. It is caused
by the concaved surface or faces close to each other
sucking the lights in. Lesser light rays can bounce out
from these areas, which causes these areas to be darker.
This phenomenon is almost like what an acoustic Sound-
absorption Panel will do to sound.
98
Set Texturing
The Base color defines the color of the model. You can
change it to any color you want to test.
99
Creating Games with Unity, Substance Painter, & Maya
Why?
Notice that we only had variations on the roughness, and
it can create fine details already. It is always worth noting
that roughness should never be overlooked. It is, in some
sense, as important as the color, if not more important.
Generators
Generators are an essential feature of Substance Painter.
Generators generate colors based on the information and
setting you give. The most common usage of generators
100
Set Texturing
101
Creating Games with Unity, Substance Painter, & Maya
102
Set Texturing
Why?
We created a fill layer; make the value of its height 1, and
use a mask to define where the height is. By doing so, we
are now able to go back to the fill layer and change its
height value to anything else. We could choose to create
a new paint layer and define the height we want to paint
in the brush settings, but then it is harder to change the
height value later.
103
Creating Games with Unity, Substance Painter, & Maya
change the size of the brush. Hold down Ctrl + right mouse
button and go up and down to change the softness of
the brush. Hold down Shift + left mouse button and go
up and down to rotate the brush. Hold down Shift + left
mouse button and go left and right to change the opacity
of the brush.
104
Set Texturing
Why?
Anchor points are references of a texture. Our Outer Panel
Mask anchor point is a reference of the result of the layers
under it and inside the mask of the OuterPanel layer.
The fill layer we added to the mask of the Steel Painted
Scraped Dirty folder is using that anchor point. So it is
referencing the same mask we painted for the OuterPanel
layer. That is why where we paint white for the mask of the
OuterPanel, we also see the Steel Painted Scraped Dirty
appear.
105
Creating Games with Unity, Substance Painter, & Maya
FIGURE 3.8 Toggle symmetry and place it for the square floor piece.
106
Set Texturing
107
Creating Games with Unity, Substance Painter, & Maya
108
Set Texturing
109
Creating Games with Unity, Substance Painter, & Maya
110
Set Texturing
111
Creating Games with Unity, Substance Painter, & Maya
112
Set Texturing
113
Creating Games with Unity, Substance Painter, & Maya
114
Set Texturing
115
Creating Games with Unity, Substance Painter, & Maya
116
Set Texturing
FIGURE 3.22 Limit the details to the top faces of the floors.
117
Creating Games with Unity, Substance Painter, & Maya
FIGURE 3.23 Use the same material to get started on the walls.
Why?
So, where are the orange panels? The answer is they have
no proper mask yet; neither do the cables. All Substance
Painter remembers is that we painted something in the
area of the floors, not on the walls; they are physically
not at the same spot in the scene. Even if they were, the
painting we did for the floor would not work for the walls.
We have to repaint them for our wall models.
118
Set Texturing
FIGURE 3.24 Toggle the visibility by clicking on the little eye icons.
119
Creating Games with Unity, Substance Painter, & Maya
FIGURE 3.26 Extra Curvature generator to create edgewear for the extra panels.
Why?
We unloaded the curvature map because we do not want
the baked curvature to affect the mask. We only want
the painted height of the extra panel to have edgewear.
Given the proper Micro Height, the Curvature generator is
perfect for generating edgewear.
120
Set Texturing
FIGURE 3.27 The result that shows all the edgewear for the panels.
121
Creating Games with Unity, Substance Painter, & Maya
Why?
You may argue that using an existing material shipped
with Substance Painter is not a good idea. After all, other
people may use it too. But we are not using it as it is,
we can combine multiple materials and get something
unique enough.
Levels
Levels is a typical color adjusting tool. The graph of the
levels shows the color distribution of the color from black
(left side) to white (right side). There are three Pins on
top of the graph. The black pin represents the total black
color of the spectrum. The gray pin represents the mid-
tone, and the white pin represents the total white color.
Dragging them around clamps and shifts the color of the
image. For example, drag the black pin to the middle, and
any color darker than the mid-tone before becomes total
black. Drag the gray pin anywhere, and the color of that
point becomes the mid-tone. The two pins at the bottom
of the graph remap the color again. The color the black
pin is at is used as black. The color the white pin is at is
used as white color. The rest of the color is interpolated
between these two colors.
122
Set Texturing
Why?
First of all, the UV Random Color generates a random color
for each UV island. The Levels then tighten the colors up
to either black or white. This way, half of the cables have a
mask of white, and the other half have black.
123
Creating Games with Unity, Substance Painter, & Maya
124
Set Texturing
FIGURE 3.32 The material created for the cable base the cable wrapper.
125
Creating Games with Unity, Substance Painter, & Maya
FIGURE 3.33 Use Steel Gun Painted as the material for the pipes.
126
Set Texturing
127
Creating Games with Unity, Substance Painter, & Maya
Why?
We don’t have too much happening on this glass
material. The shader of the game engine is going to be
very different for things like transparency. We are going
to define these attributes in the game engine when we
create these materials.
128
Set Texturing
Assignment: Texturing
the Rest of the Models
The way we texture the props and the hero asset is the
same way we texture our modular piece. Figures 3.39–
3.44 show the result of the textures we did. The only new
thing here is that for the screens, we added an Emissive
channel to the shader to allow emissive input to make
129
Creating Games with Unity, Substance Painter, & Maya
FIGURE 3.40 Completed versions of rounded set pieces, including glass shaders.
FIGURE 3.41 With a dark base, objects like this will contrast well with the orange
components.
FIGURE 3.42 Using a similar pallete keeps elements part of the same universe while
providing contrast with the orange walls.
130
Set Texturing
131
Creating Games with Unity, Substance Painter, & Maya
Conclusion
Texturing takes time, but it is more fun to do. However,
while textured models are great to see, we’re not done.
Now, we need to get our textured assets into the game
engine, set up the materials, and assemble the completed
modules into a playable level.
132
CHAPTER 4
133
Creating Games with Unity, Substance Painter, & Maya
Game Engines
Game engines are software packages built to assemble
games. Think of a game engine as “middleware” where
not a lot of visual assets are created, but rather a place
where assets are assembled and made interactive. Game
engines have built frameworks or modules for rendering,
inputs, physics, AI, networking, UI (user interface),
VFX, and audio. Usually this framework is leveraged in
an “editor” that allows for asset assembly to happen.
Importantly, this is where interactivity through scripting is
created.
Unity
For this volume, our game engine of choice is Unity. Unity
has made a name for itself with its nimble authoring
cycle and ease of use. While Unity has always been
playing catchup with its biggest competitor (Unreal
Engine) in visual fidelity, the benefits in creating efficient,
lightweight, and quickly iterated games has made Unity
a quick riser in the world of game engines. Particularly in
the world of mobile, AR, and VR, Unity has nabbed a big
part of the market.
Because different devices have different levels of power
(measured in computations per second on a processor,
amount of data stored in random access memory, and
both for video cards), games are built with target devices
in mind. A game build for an PS5 is not going to run on
your iPhone (or presently, even on most PCs for that
matter). Similarly, a game that passes for beautiful on an
Android device feels woefully under-designed on your
134
Unity Asset Creation
135
Creating Games with Unity, Substance Painter, & Maya
136
Unity Asset Creation
FIGURE 4.1 Unity Hub’s installation window. For now, just Skip Install Wizard so we can choose what to install with more
control.
137
Creating Games with Unity, Substance Painter, & Maya
FIGURE 4.3 Unity inviting you to install modules. For now, only make sure that Documentation is checked – leave the rest off
for now.
138
Unity Asset Creation
Why?
After checking, several things will actually be installed.
Unity Hub will install Unity (of course), but will also
install a version of Visual Studio, which we’ll use later to
write code. Go ahead and run through all the steps for
this installation. We will talk much more about Visual
Studio later.
139
Creating Games with Unity, Substance Painter, & Maya
Why?
From now on, whenever you plan to work on this Unity
project, access it via the Unity Hub. Open Unity Hub and
this new project should appear in the list of projects.
Double-click its name there, and this will open Unity for
you and open the project within it.
140
Unity Asset Creation
FIGURE 4.6 Optimizing the layout so that the Project window shows a single-
column layout.
Game – This is what the player will see when playing your
game. It is the view of one of the cameras in the scene.
When you play the game (using the Play/Pause/Step
buttons at the very top of the interface), it is this window
you will be interacting with. If you have two monitors, it is
often helpful to drag this tab (just click and drag the tab
that reads Game) onto that second monitor. This allows
you to play full-screen on one screen, while still observing
what’s happening in the Scene window. In this Game
window, there are lots of pull-down and button menus
at the top that we will be exploring in the future.
141
Creating Games with Unity, Substance Painter, & Maya
Why?
Notice that this is inside the folder that is storing this
Unity project. Specifically, it is saving it inside a folder
called Assets. It is important that you don’t save anything
outside of the Assets folder for use in this Unity project.
In fact, it’s important that generally you don’t mess with
where files are placed within your Unity project folder in
any other place but Unity. If you need to delete an asset,
do it in Unity (not in your Finder). This will ensure that you
142
Unity Asset Creation
FIGURE 4.7 Streamlined project. We’ve eliminated assets Unity included as tutorial
files to keep the project lean.
FIGURE 4.8 Our organized Unity project. Folders here have been created into which
we’ll import a variety of assets to build our level.
143
Creating Games with Unity, Substance Painter, & Maya
Why?
History can be of great help when modeling in Maya,
but is not of help when working in a game engine. A
model with History will bring in strange empty nodes
into your game engine that can cause problems later.
For static meshes – meshes that don’t move, getting rid
of any nodes that might still be hanging on will make
sure you only push geometry (with its UV layout) to the
game engine.
144
Unity Asset Creation
FIGURE 4.9 Marquee select all the geometry (not the groups) and then freeze the transformations.
Why?
Freezing Transformation resets the Translate X, Translate
Y, and Translate Y to 0. Unity will interpret these models as
being at “the origin” or 0,0,0 in world space. This will make
for easy placement and manipulation later.
145
Creating Games with Unity, Substance Painter, & Maya
Why?
Again, our goal here it to export just the geometry.
We’ll get the textures from Substance Painter, and other
elements like cameras, lights, and audio will be created
or assembled in Unity. We want to pass along just the
polygons at this point.
FIGURE 4.10 Geometry imported into Unity. It’s not ready to use yet, but Unity knows about it and is ready to work with it.
146
Unity Asset Creation
Why?
Of course, this is still missing textures and shaders. We
haven’t brought those in from Substance Painter yet. And
currently it’s all one big file, which defeats the purpose of
a modular layout. Not to worry. We still have some work
to do before we can actually build with these modules.
By turning off Rig and Animation, we can make sure that
we only have the geometry in this file and nothing else.
Why?
Our plan is to use Substance presets for output. As Unity
has adjusted their Render Pipelines, Substance has
updated their presets to match. For the smoothest move
from Substance Painter to Unity, we should have the latest
presets in action.
147
Creating Games with Unity, Substance Painter, & Maya
FIGURE 4.11 Where we left off in Substance Painter for the modular_pieces_texturing file.
Why?
Lots of “why’s” here. We’re exporting directly into the
Unity project to streamline the asset movement process.
In the next steps, we’ll look at how Unity imports these
new textures it will discover in its Assets/Textures folder.
By leveraging Substance Painter’s output templates, we
can make sure and export the assets we need for our
HDRP workflow. Targas are my preferred file format as it
is lossless and will maintain its fidelity, although Unity is
pretty good at bringing in almost any image file format.
Unity only deals in 8-bit textures, so no need to export
anything larger than that.
148
Unity Asset Creation
Why?
Normal maps are strange beasts with much more data in
them that meets the eye. Marking these normal maps that
Substance Painter output helps Unity know how to deal
with these maps and how to use them.
149
Creating Games with Unity, Substance Painter, & Maya
FIGURE 4.13 Setting all the normal maps to be imported as normal maps and not default texture maps.
Why?
By extracting the materials in this way, we now are able to
manually rebuild them to use the textures we exporting
from Substance Painter. Until they are extracted like
this, they cannot be edited. Notice that these materials
(if selected in the Project window) are a shader called
HDRP/Lit and make use of the HDRP Metallic workflow.
Rebuilding Materials
So now you have a folder full of materials. These materials
are already applied to the geometry in the scene, but
without textures to define the various attributes of
the materials, they all look gray. The task now is to
rebuild the materials using the textures generated from
Substance Painter.
150
Unity Asset Creation
FIGURE 4.14 Extracting the materials so we can adjust them and plug in our
textures.
151
Creating Games with Unity, Substance Painter, & Maya
FIGURE 4.15 Plugging in the textures for each material. The naming is fairly straightforward, so plugging each texture in is just
a matter of dragging from the Project window into the appropriate slot in the Inspector window.
FIGURE 4.16 Untinting the Base Map to white to allow the texture to define the
color of the surface.
152
Unity Asset Creation
153
Creating Games with Unity, Substance Painter, & Maya
FIGURE 4.18 Finished rebuilt materials. Notice that this screenshot was taken on the
other side as earlier images. To be able to see this, the Directional Light was selected
in the Hierarchy and rotated.
154
Unity Asset Creation
155
Creating Games with Unity, Substance Painter, & Maya
156
Unity Asset Creation
FIGURE 4.20 Newly added Mesh Collider. This is the quickest, but most expensive
collider to add.
Why?
We’ve already talked about collisions, but what are
Lightmap UVs? Later we are going to bake some of our
lighting (real-time light calculations are expensive).
Lightmap UVs are a separate UV set that will store the
lighting information when we bake. Right now, this will
seem like a strange and esoteric step, but it will become
clear later.
157
Creating Games with Unity, Substance Painter, & Maya
Why?
We’re doing these three first because they are groups.
The rest of the meshes will be their own prefabs, but
these three objects are composed of multiple meshes,
but meshes that will usually be placed as a group.
158
Unity Asset Creation
Why?
Auto Exposure is the idea that the virtual camera we are
using to see the scene is automatically adjusting its virtual
aperture depending on the amount of light it senses.
Many real cameras do this (as does your eye). However,
I find it to be a real problem in virtual environments.
Both UE4 and Unity now start with Auto Exposure
activated, and it means that as you change the light
intensities of the lights in the scene, the camera is
automatically adjusting at the same time. This means
159
Creating Games with Unity, Substance Painter, & Maya
FIGURE 4.21 Adjusting the camera to Use Physical Camera. We’ll change this later.
Why?
It’s not necessary, but getting the first piece in the middle
of the world makes for easier understanding of where all
the pieces are laid out.
160
Unity Asset Creation
FIGURE 4.22 Moving the duplicated floor away from the first just to see the two separate pieces.
161
Creating Games with Unity, Substance Painter, & Maya
FIGURE 4.23 Using the Vertex Snap method to snap one floor to another.
162
Unity Asset Creation
FIGURE 4.24 Rotating the placed wall module. Note that holding Ctrl down will
snap the rotation by 15 degrees at a time.
FIGURE 4.25 Using the Move/Translate tool and snapping to place the wall.
163
Creating Games with Unity, Substance Painter, & Maya
FIGURE 4.26 Duplicating the floor to make the ceiling. Notice that lighting has been turned off for this screenshot (see Tips and
Tricks).
164
Unity Asset Creation
FIGURE 4.27 Hallway created by duplicating one section. Be sure to use vertex snapping to make sure they are snug with
each other.
165
Creating Games with Unity, Substance Painter, & Maya
Why?
HDRP has some new ways of measuring light intensities –
not all of them easy to use. The default unit for lights
are Lumen. But the values needed for these are huge
(six million or so). Numbers that large are goofy to work
with, so I prefer using Ev 100 as the unit. This means,
sometimes, fine-tuning lights is tweaking in the tenths,
hundredths, or even thousandths of a unit, but it’s still
preferable to Unity showing a value of “1.31768e + 07”!
FIGURE 4.29 Tracking down the glass material and changing it to a Transparent shader.
166
Unity Asset Creation
FIGURE 4.30 Adjusting the Transparency Inputs by controlling the Refraction Model
(Box) and Index of Refraction (1.7).
FIGURE 4.31 Continued exploration with the Transparency Inputs (using Sphere
Refraction Model and a non-white Transmittance Color).
167
Creating Games with Unity, Substance Painter, & Maya
168
Unity Asset Creation
Conclusion
There’s plenty more to do. Notice that there are other
lights that need adjusted materials, and there are things
like monitors that also likely need emissive materials. Get
in there and start experimenting. Sometimes, learning
works best by pushing buttons and sliding sliders once
you know where they are and observing the results.
169
Creating Games with Unity, Substance Painter, & Maya
170
CHAPTER 5
171
Creating Games with Unity, Substance Painter, & Maya
172
Unity Level Creation
173
Creating Games with Unity, Substance Painter, & Maya
FIGURE 5.1 Adjusting our Project Settings to allow for ambient light throughout (although we’ll get rid of this later).
Why?
There are lots of ways to override these default settings.
Unity works with an idea called Volumes (Post Processing,
Sky and Fog Volumes, etc.), but for the scope of this book,
we’ll generally work with adjusting the default settings at
this point. There may be times you want to swap profiles
as you move from Level to Level (Scene to Scene using
Unity’s language); but for now, since we’re working with
one Scene, adjusting the default settings works like a
Global effect and will be easier to manage.
174
Unity Level Creation
FIGURE 5.2 Three floor_01 prefabs duplicated and snapped into place.
175
Creating Games with Unity, Substance Painter, & Maya
176
Unity Level Creation
FIGURE 5.4 Snapping the corner tiles down to make room for grates.
FIGURE 5.6 Adding extra visual interest by swapping out the units beneath the
grates. Alternatively, you could also use floor_03 (although you’d need to place more
of them).
177
Creating Games with Unity, Substance Painter, & Maya
FIGURE 5.8 The Tool Handle Position settings to change where the tool handles
appear on selected objects or (importantly) groups of objects.
Why?
Lots going on in this step. Let’s break it down. The Tool
Handle Position (Pivot/Center) determines where the
handle (Move/Rotate/Scale) is displayed. If this is set to
Pivot, and a group of objects are selected, the handle
will appear on the last object selected. If set to Center,
Unity finds the geometric center of the group of objects
centered and displays the handle there. Then, when F is
pressed, Unity will center its view on the geometric center
of the group of selected objects. This becomes handy
because when a new object is created in Unity, it is created
at the view center. So being focused on the geometric
center of a group of objects means the empty GameObject
(no geometry of its own – just a container) is created right
in the middle of the objects its meant to contain.
178
Unity Level Creation
FIGURE 5.9 Wall placement using wall_01. Notice that lighting has been turned off
for this screenshot by hitting the Toggle Scene Lighting button (the little light bulb at
the top of the Scene window).
179
Creating Games with Unity, Substance Painter, & Maya
FIGURE 5.10 Filling in the corners with Turning_wall_01. The inset shows the
vertex used to snap most efficiently.
Step 14: Build the door. Figure 5.11 shows the door
prefab and window_01 (with window_01_glass)
stacked above it.
180
Unity Level Creation
FIGURE 5.13 Finishing off the walls using wall_01 and wall_corner_frame prefabs.
181
Creating Games with Unity, Substance Painter, & Maya
FIGURE 5.15 Ensuring that our glass prefabs will let light pass through it by setting the geometry to not Cast Shadows.
182
Unity Level Creation
Why?
Now that there’s a ceiling on the room, it’s dark in there.
Well, it’s dark until the camera compensates. Even
though the material for the glass panes may be set to
be transparent, the geometry still thinks it should stop
light. By making sure Cast Shadows is set to off, light can
stream through the glass. Importantly, by doing this to
the prefabs, every place we have placed the prefabs will
automatically use these settings.
Why?
You probably noticed that before we turned the Emission
Intensity back to 0, those lights were all aglow. This is
FIGURE 5.16 Light streaming through our newly non-shadow casting glass panes.
183
Creating Games with Unity, Substance Painter, & Maya
FIGURE 5.18 Dressed set. Feel free to adjust as you see fit.
184
Unity Level Creation
Kitbashing
To “kitbash” is to take a kit of modules and bash them
together into endless variations. You can buy kits to bash,
although here we’ve created our own (which is really the
professional way to work). Hopefully in the previous steps
you got a good idea of the process of placing prefabs,
snapping them into position, and/or rotating, moving,
scaling the parts into a cohesive whole.
For the rest of this chapter, we will move quite a bit faster.
The reason is the specific pieces of the kit that you bash
together aren’t terribly important and you can deviate
from the proposed spaces all you want. However, we
will provide some quick suggestions on putting shapes
together to provide some guidance of the usefulness of
the various pieces of our kit.
Why?
A module here that is two units long allows for the grates
to be mirrored so the long hallway will have a more
interesting breakup.
185
Creating Games with Unity, Substance Painter, & Maya
186
Unity Level Creation
187
Creating Games with Unity, Substance Painter, & Maya
188
Unity Level Creation
FIGURE 5.24 Building out the extended floor for a turn in the hallway.
FIGURE 5.25 Building in the curves of the hallway with our pre-built curved wall
modules.
189
Creating Games with Unity, Substance Painter, & Maya
190
Unity Level Creation
FIGURE 5.29 Roughed out CameraRoom. Note that “CameraRoom” refers to the
name of the group all of these assets end up being the children of. Note that there’s a
temporary Point Light in the scene to help us see what’s happening in there.
191
Creating Games with Unity, Substance Painter, & Maya
192
Unity Level Creation
FIGURE 5.34 More complicated module collection for one side of the long hallway.
193
Creating Games with Unity, Substance Painter, & Maya
FIGURE 5.35 Utilizing some of the other modules we have to allow us a glimpse
outside, although we’ll adjust this in a bit to allow for the Armory.
FIGURE 5.36 Creating the small armory using some of the arc modules.
194
Unity Level Creation
Step 47: Finish off the lower walls. Figure 5.40 shows
one solution that includes some glass to see
outside. Notice that importantly, there is another
entrance (or for us exit) on the far side where we
will face the final boss.
195
Creating Games with Unity, Substance Painter, & Maya
FIGURE 5.42 Finishing off the dormers with windows and Tilt_04.
196
Unity Level Creation
FIGURE 5.43 Catwalks and stairs to begin filling out the space. This screenshot
taken with the ceiling turned off in the Inspector.
197
Creating Games with Unity, Substance Painter, & Maya
Tutorial Conclusion
There are lots of ways to build an interpret this level.
Jingtian Li’s modules are designed in a way to allow
for most any configuration. Jingtian Li’s layout of
the boss room, for instance, differs significantly than
the interpretation seen in Figure 5.46 – and yours
undoubtedly will as well. No matter how you layout the
level, you’ll likely eventually adjust.
198
Unity Level Creation
199
Creating Games with Unity, Substance Painter, & Maya
Why?
This file is a Unity Package File, which are zipped archives
that can include anything from models to animations,
to scripts, to all of the above. Although up to now we’ve
simply saved things that we planned to use in Unity into
the Assets folder, for Unity Package Files we need to do
this just a little differently.
Why?
Notice that this includes quite a few items. There are
several scripts in there, readme, and even some geometry.
This is the power of a Unity Package – it’s not only an
import, but it maintains the proper file structure for the
imported assets.
200
Unity Level Creation
FIGURE 5.47 Importing a Unity Package. In this case, we’re bringing in the scripts and file structure for the Unity-built
FPSController.
Why?
FPSController is a weird looking thing at first glance. There
are a lot of gizmos drawn there. You can see the green
capsule shape that is the collider, the camera, the audio
source, the frustum of the camera, etc. Don’t get too
caught up on any of it for now. We’ll be looking at all the
components attached to this over time.
201
Creating Games with Unity, Substance Painter, & Maya
Why?
Two cameras in a scene can be bad news. For one thing,
it means that the scene is being drawn twice (more
work than we want for the computer to do). For another,
both cameras have Listeners on them that define how
the player hears sound in the game – think of them as
microphones. If there are two Listeners, Unity isn’t sure
which to capture sound from. For now, we want to make
sure the only camera in the scene is the one attached to
FPSController.
202
Unity Level Creation
Why?
Unity’s default FPSController is two units tall. Two units in
Unity is 2 meters. This means the default character is over six
and a half feet tall. Resizing to 0.8 makes the character much
closer to the size of the character we will actually play as.
FIGURE 5.49 Rough settings for the Point Light we’ve attached to the FPSController
in the scene.
203
Creating Games with Unity, Substance Painter, & Maya
FIGURE 5.50 The Play button in Unity to try experiencing your work in the Game
window.
Why?
So far we’ve done a lot of modeling, but no real lighting.
You may have created a few point lights in the scene to
help with modeling, but otherwise the level is going to be
pretty strange. This Point Light is a crude way of sticking
a lantern on our head so we can see things as we move
around. It’s not going to be a terribly flattering way to view
our level (that will come next chapter when we light it), but
we’ll be able to see what’s happening in the scene.
Why?
Because everything has a collider on it, we luckily
don’t fall through the floor. But that means we also,
unluckily, can’t walk through the doors. Later, we’ll
create some script that will open the doors as we get
close. For now, we need to adjust them so we can walk
through them.
204
Unity Level Creation
FIGURE 5.51 To exit the Prefab editor, just click on Scenes at the top left of the
Scene window.
Why?
By turning off the Mesh Collider for the door prefab, all
the doors that we’ve place everywhere in the scene will
now no longer have a collider. This means we’ll be able to
just walk through the doors. It’s the power of the prefab.
If we make changes to the original, all the instances of that
prefab inherit that change.
Conclusion
Lots still to do. Hopefully, at this point, you feel
accomplished that you’ve built the level, but unsatisfied
as the lighting is so lame. Lighting is a critical part of the
design process that has not only functional uses (if we
can’t see it’s a boring game) but also artistic functions as
it can be one of the most effective ways to add ambiance
and mood to a scene.
205
Creating Games with Unity, Substance Painter, & Maya
Post Script
In the next chapter, when we do lighting, our concept is
that our incursion is happening at night under the cover
of darkness. The lighting schemes are more dramatic
that way. However, there certainly is a case for a daytime
lighting scenario. The problem is that we can look out the
window and see the outside of our facility and it doesn’t
look good. We’ve constructed the facility to be lovely from
the inside, but the outside is just the backsides of our
interior shapes (Figure 5.52).
FIGURE 5.52 Lovely daytime lighting – except that we can see parts of the facility
we oughtn’t.
206
Unity Level Creation
Having said that, we are likely to not see much of this in our
version of the next chapter because of our lighting choices
there. But it’s an easy thing to implement if you need it.
FIGURE 5.54 Blocking out unsightly areas with a bit of free downloaded
photogrammetry.
207
CHAPTER 6
209
Creating Games with Unity, Substance Painter, & Maya
210
Lighting and Baking
211
Creating Games with Unity, Substance Painter, & Maya
Unity Lights
Let’s start by first taking a quick look at the different
types of lights that Unity provides. For a quick exercise,
Save your scene (File>Save) and create a new scene
(File>New Scene) as a playground. In this playground,
create a plane (GameObject>3D Object>Plane). Hit F to
focus on it.
212
Lighting and Baking
FIGURE 6.2 Directional lights throw parallel lights from infinitely far away an
infinite distance. Notice by default they don’t cast shadows.
213
Creating Games with Unity, Substance Painter, & Maya
214
Lighting and Baking
215
Creating Games with Unity, Substance Painter, & Maya
Why?
We’re working on lighting this for the evening. As such
we don’t want a bunch of random lights we may have
inserted during building in our scene. We will be working
with practical lights (lights the player can clearly see the
source of), and mood lights, but we want to start with a
tabula rasa.
216
Lighting and Baking
Why?
AllSky is a nice collection of assets for – you guessed
it – skies. The paid version is worth every penny, but the
free version has some nice assets we can make use of.
Incidentally, skyboxes (the asset used to contain skies) can
be created from many other downloadable assets. Using
something like HDRI (high dynamic range images) can
determine how the ambient light in the scene appears. As
an example, Figure 6.6 shows the sample scene using a
variety of HDRI-based skies. Besides the obvious changes
to the color of the sky, the results on the geometry are
also clearly seen.
FIGURE 6.6 Identical lighting, with different HDRI-based skies and the resulting
changes in ambient light (global illumination).
217
Creating Games with Unity, Substance Painter, & Maya
FIGURE 6.7 A Cubemap asset. Notice there are lots of other assets in the folder, but
the Cubemap is the required one to define the sky.
Why?
That Automatic exposure we were working with was fine
while modeling. But with a camera that is continually
adjusting, it is impossible to light. For instance, with
218
Lighting and Baking
FIGURE 6.9 Setting the camera exposure to a fixed amount. Notice the inside of the level will be very dark – just like we need it.
219
Creating Games with Unity, Substance Painter, & Maya
FIGURE 6.10 Getting ready to light (the Game window will be really dark). This is the Scene window with lighting temporarily
turned off.
220
Lighting and Baking
Why?
What a mess. It’s actually pretty easy to clean up, but
this is often what happens with first guesses. Let’s break
down what is happening there. The dirty volumetric light
and big rings on the floor are because the light course
is up inside of the geometry and the rings of the light
are casting a shadow. The intensity might be a little hot
as well.
221
Creating Games with Unity, Substance Painter, & Maya
FIGURE 6.12 Initial guess at the necessary settings for the spotlight.
222
Lighting and Baking
FIGURE 6.14 Adjusting the Near Plane changes where Unity begins calculating
shadows from.
223
Creating Games with Unity, Substance Painter, & Maya
clear of the too even, too “computery” look that the Spot
Light currently has.
224
Lighting and Baking
FIGURE 6.16 Increasing the Cookie Texture Atlas to allow for multiple cookies.
Why?
A Texture Atlas is a single file that holds the textures for
multiple objects. In this case, Unity is going to create an
atlas to store cookies. A 1024 atlas can store four 512 × 512
cookies. It stores these cookies in memory (which ties
up resources) but doesn’t require extra draw calls (the
process of actually drawing something) if more than one
is in the scene. This is new to Unity, but if you don’t clear
space in the Cookie Texture Atlas, Unity will complain
loudly when it is applied to a light.
225
Creating Games with Unity, Substance Painter, & Maya
226
Lighting and Baking
Why?
In previous versions of Unity, the images actually had to
be imported as Cookies. But HDRP prefers that they come
in as Default setting. However, the Cookie texture needs
to know which parts are to let light through, so changing
the Alpha Source to “From Gray School” allows Unity to
add an alpha channel to the image and allow light to
pass through white pixels but be stopped by black ones.
Finally, changing the Max Size to 512 makes sure that both
images come in as 512 × 512 and fit into our 1025 Cookie
Texture Atlas.
227
Creating Games with Unity, Substance Painter, & Maya
FIGURE 6.19 Applying the changes made to a single instance of a prefab to all
instances of a prefab.
Why?
Working in the Prefab Editor has its limitations. We never
would have been able to see what intensity was
appropriate for the light (for example) in that interface. But
when we changed the settings in the Scene window for the
Spot Light, it was only changing that particular light (not
all the lights attached to all the other ceiling_light_01s). By
applying the Overrides, we have instructed Unity to apply
these changes to all instances of the prefab (Figure 6.20).
228
Lighting and Baking
229
Creating Games with Unity, Substance Painter, & Maya
Step 18: Play the game and see what it looks like from
the player’s perspective. Make adjustments as
needed. Figure 6.23 shows choices where both the
Area Light and Spot Light used Color Temperature
and were pulled a little colder (bluer).
230
Lighting and Baking
231
Creating Games with Unity, Substance Painter, & Maya
FIGURE 6.27 Without and with the Directional Light. Each tells a different tale, and
there isn’t necessarily a better choice. You chose.
232
Lighting and Baking
Baking
Currently, everywhere the player looks they are seeing
real-time lighting. There are some benefits to this. For
instance, if we wanted to design game play that allowed
some of the boxes to be moved, real-time lighting would
be needed to update as the pieces moved. However, there
are also some drawbacks. For instance, if you have a small
video card you might be starting to run up against some
performance issues where your machine is unable to draw
the scene smoothly or interact quickly. Further, the lights
that are in the scene light the surfaces they strike, but that
light largely dies there. It does not bounce and further
illuminate other surfaces. This means that the ceilings
(that were already dark) are completely black (which in
most cases would not be accurate in the “real world”).
Why?
Mixed lights are those that react to movement when
close, but the results of the light can be baked into the
233
Creating Games with Unity, Substance Painter, & Maya
FIGURE 6.28 Setting the lights in each prefab (and therefore all the lights in the
scene) to be Mixed. This means they will be involved in the baking process.
Why?
If an object moves, the light shouldn’t be baked for it
(remember the example of moving a chair and leaving
the shadow behind?). By marking the room (and all of
its children) Static, we are indicating to Unity that these
objects will not move and should be used in the baking
calculation.
234
Lighting and Baking
235
Creating Games with Unity, Substance Painter, & Maya
FIGURE 6.30 One hallway prebaked on the left and postbaked on the right.
Camera Adjustments
and Postprocessing
Step 20: Adjust exposure. There is no need to be
satisfied with the results of the bake – especially
if it is too dark. Remember that we can work with
the exposure settings for the camera as well.
Open Project Settings (Edit>Project Settings)
and again go down to Volume Component
and expand Exposure. There, change the Fixed
Exposure up or down. Figure 6.31 on the left
shows a Fixed Exposure setting of 8.5 and
the one on the right shows 7.5. No baking, no
relighting, just adjusting how the camera sees
the extant lighting scheme.
Step 21: Create a Global Volume to better control
the Post Processing. Choose GameObject and
choose Global Volume. In Hierarchy, rename
this CameraEffects. In the Inspector, under the
Volume section create a new Profile by clicking
the New button.
Why?
Creating a Global Volume like this allows us to control
things like the Post Processing Effects. Postprocessing is
FIGURE 6.31 Adjusting the camera’s exposure time to change the light intensities.
The left image is using a Fixed Exposure of 8.5, while the right is showing 7.5.
236
Lighting and Baking
how Unity gives the last bit of polish to a scene. It can also
be a very expensive process. The default HDRP has loads
and loads of postprocessing going on (including irritating
things like Motion Blur). By creating a Global Volume and
then creating a Profile for that volume, we can take more
direct control over how the image is processed after the
geometry is rendered but before its shown to the user.
FIGURE 6.32 Without ACES Tonemapping and adjusted Ambient Occlusion on the
left. With adjustments on the right.
237
Creating Games with Unity, Substance Painter, & Maya
FIGURE 6.33 Extensive control over postprocessing effects can allow for a lot of detailed look development.
238
Lighting and Baking
FIGURE 6.35 Beauty shot using some volumetric light to shield the empty outside.
239
Creating Games with Unity, Substance Painter, & Maya
FIGURE 6.37 Beauty shot of a dramatically lit entrance to the final boss.
240
Lighting and Baking
Final Challenge
Another design choice could be a very low lighting situation
full of dark and foreboding shadows. The player, luckily,
has a flashlight so that everywhere they look, the scene
(and the resulting spooky shadows it creates are built).
Think about creating a Spot Light (make sure to use the
Flashlight_Cookie) and attaching it to the player’s camera
(FirstPersonCharacter). Be sure that its casting shadow, and
bit of light adjustment can help too (Figure 6.39).
241
Creating Games with Unity, Substance Painter, & Maya
Conclusion
Time for you to explore. Now that the basic tools are in
your possession, you can start twisting and tweaking
them to your nefarious will. Much of the creativity process
of lighting is via experimentation so try something; if it
doesn’t work, tweak and try again.
For now we’re going to leave the set behind. It’s time to
work on characters for our scene.
242
CHAPTER 7
Character Modeling
243
Creating Games with Unity, Substance Painter, & Maya
Concept Art
Concept art is one of the most critical steps of character
development and should never be overlooked. The
back story, environment, occupation, and all other parts
of a character are thought through before the visual is
touched. Visual appearance also takes many iterations to
achieve the desired result. Our concept here is Ellen Mara.
She is one of the genetic clones of a mindless killing army
but somehow becomes self-aware and want to escape
from fate. The design we settled on is shown in Figure 7.1.
Style Sheets
It is critical to have a clean style sheet that lays out the
full character, and it is more practical to avoid fancy
shading and use clear lines to represent the shapes. It is
also essential to have different views of the character to
match each other accurately. For example, the bottom of
the chin should be in the same location in both the front
and side view. There are two different poses we can model
our character in: T pose and A pose. T pose has the arms
straight, while A pose has the arms down naturally. We
choose A pose for a better definition of the shape of the
shoulder. Otherwise, the shoulder of the character in a
natural pose has to be defined by rigging.
244
Character Modeling
Workflow
Through the years of development, the workflow to make
a character has changed a lot. The modern workflow
mostly has a sculpting software called ZBrush involved.
However, to limit the amount of software and the cost
to follow this book, we are going for a more traditional
approach – box modeling. Box modeling may not be the
state-of-the-art workflow, but it is the best practice to
teach topology, which is technically critical for rigging and
animation. On the other hand, it is also going to force the
artist to think about big shapes and proportions first.
Polycount
Polycount is one of the first things to think about before
start making the model. It is drastically different based on
the targeted platform, engine, and how many characters
are going to appear on the screen. Polycount becomes
lesser of a performance hit compared to the amount
of lighting, shadowing, and textures, and we can safely
assume an amount of 30k tris acceptable. This is not to say
that we should reach 30k tris, finding the right balance
between quality and performance is always needed.
245
Creating Games with Unity, Substance Painter, & Maya
Why?
The two image planes are references we need to get an
accurate result. We are moving them away from the center
to avoid clipping between our geometry and image
planes.
Why?
This step is to keep the perspective view clean, but it is
optional. Some modelers may think having image planes
visible in the perspective view is more helpful.
246
Character Modeling
Eyeball
Step 10: Create a polygon sphere and rename it
Ellen_l_eye_geo. This sphere is going to be the
eyeball (Create->Polygon Primitives->Sphere).
Step 11: Reduce eyeball polycount. Select Ellen_l_
eye_geo, go to the channel box, under the
INPUTS section, click polySphere1, and change
the subdivision Axis and Subdivision Height
to 16.
Why?
Although eyeball is important, our gamer is very unlikely
to see it terribly close; reducing its polycount can help
increase the frame rate in the game. Note that based on
the type of the game, the subdivision level can very.
Step 12: Fix eye topology. Select the top center vertex
of the eyeball (this is the front of the eye), holding
down Ctrl, and then hit the delete button on the
keyboard. We are now rid of all the triangles
in the center. Switch to the Multi-Cut tool and
connect the points to a grid-like topology
(Figure 7.3).
Why?
Any vertex that has more than four edges connected is
called a pole. Pole is notoriously bad for smooth shading,
especially when it has a lot of lines connected to it.
Because the eye is one of the most important parts of a
character, we choose to recreate the topology of the front.
247
Creating Games with Unity, Substance Painter, & Maya
Why?
The shape of the eyeball is not exactly a ball. The corneal
area is bulging out a little bit more, mimicking the same
shape that will help the refraction and highlight of the
eyeball.
248
Character Modeling
FIGURE 7.6 Match the eyeball model with the reference images.
249
Creating Games with Unity, Substance Painter, & Maya
FIGURE 7.7 Use the Quad Draw Tool to draw a face for the eyelid.
Why?
Quad Draw Tool is a re-topologizing tool that allows us to
create the topology for any geometry. We use it to get the
correct curvature of the eye. One important usage of this
250
Character Modeling
Step 20: Refine the eyelid shape. Turn off the live
object, switch to the Selection tool, and go to
object mode. Move the eyelid model forward
a little, so there is a gap for the thickness of the
eyelid. Go to side view and drag individual points
to match the shape to the contour of the eyelid in
the side view.
Step 21: Refine the inner corner. Select the two
endpoints of the inner corner; use Move, and soft
selection to drag the inner corner area forward
(Figure 7.9).
Why?
Although the outer corner of the eyelid rests on the side
of the eyeball, the inner corner does not. Underneath
the inner corner of the eyelid, there are structures like
caruncle and Papilla lacrimalis, which displace the inner
eye corner forwards. That’s why we drag it forward.
251
Creating Games with Unity, Substance Painter, & Maya
252
Character Modeling
Why?
Step 23 seems to be a lot of work, but this part is a
must-have to make the eyes look good. We are
trying to achieve high-level results here; feel free
to skip this if you are not trying to make a very
detailed eye.
Step 24: Round up the ridge of the eyelid. Select the
loop at the turning edge of the upper eyelid that
transitions from its front to its thickness, drag it
up a little bit. Select the same loop of the lower
eyelid and drag it down. This is to make the
correct curvature of the transition of the eyelids;
see Figure 7.12 for detailed illustration.
Step 25: Soften the normal. Go to object mode, make
sure Ellen_body_geo is selected, hold down
Shift + right mouse button, and then choose
Soften/Harden Edges->Soften Edge.
Why?
We tend to limit our polycount, but we do not want to see
hard polygon edges. Soften Edge command helps smooth
out the shading between edges of the faces.
FIGURE 7.12 Drag the edges to round up the ridge of the eyelid.
253
Creating Games with Unity, Substance Painter, & Maya
FIGURE 7.13 Create an edge loop that extends to the edge of the eye socket.
FIGURE 7.14 Add additional loop to define the inter detail of the eye socket.
254
Character Modeling
FIGURE 7.15 Add more loops to define the curvature of the eye socket.
Why?
From Step 26 to Step 28, we used a workflow of mark
the edge first and then added detail in the middle. This
workflow ensures that we can get the bigger shape first
and never lose control.
255
Creating Games with Unity, Substance Painter, & Maya
256
Character Modeling
Why?
The edge flow is the only tool to represent turns of any
structure. We built the loop in Step 32 to accurately
represent the structural change of the nose and eyebrow,
almost like how you would place the bricks on an arch.
257
Creating Games with Unity, Substance Painter, & Maya
258
Character Modeling
259
Creating Games with Unity, Substance Painter, & Maya
Why?
Making the contour of different parts gives us the
framework of the shape. Once finished, all we need to do
is to fill in the gaps. Topology is basically edge loops like
what we did in Step 36 with grid-like internal fills.
Step 38: Fill the side of the nose. Select the hole of the
side of the nose, hold Shift + right mouse button,
and choose Fill Hole. Use the Multi-Cut tool to
fill in the geometry. In Figure 7.24, highlighted
lines are the newly added lines to get a clean
topology. Drag the vertices around to refine the
shape of the side of the nose.
Step 39: Fill the tip of the nose the same way we did
in Step 38 (Figure 7.25).
260
Character Modeling
Mouth
Step 40: Mouth. Extrude from the bottom of the nose
to create the philtrum. From the bottom of the
philtrum, extrude out the loops for the lip. Add
extra loops to help define the shape better. Be
careful about the curvature of the model from
different angles. It is very easy to end up with
a flat result, so make sure that the arc of the
contour is always managed (Figure 7.26).
Step 41: Fill in the gaps between the mouth and the
nasolabial fold. Bridge the outer edge of the lips
to the inner edge of the nasolabial fold; if there is
a mismatch on polycount, just add more loops. A
pole is needed to sort out the upper right corner
mesh flows (Figure 7.27).
FIGURE 7.27 Fill in the gaps between the mouth and the nasolabial fold.
261
Creating Games with Unity, Substance Painter, & Maya
262
Character Modeling
Step 44: Fill in the side of the face. We can fill the side
of the face using the same method as in previous
steps (Figure 7.30). The outer corner of the eye
does not have enough polycount to connect to
the other side, so two more loops were added to
compensate that. They are marked in Figure 7.30.
Step 45: Fill in the top of the head. The topology
of the top is basically a cube smoothed twice.
The important thing is to find the two corner
points, and they are indicated in Figure 7.31. It
is these two points that redirect the flows of the
polygons. After these two points, geometries
either go from front to the back or from side to
middle. Note that Grab and Smooth sculpting
were used to achieve a smooth result after
getting the topology working.
263
Creating Games with Unity, Substance Painter, & Maya
Ear
The ear might be not as important as the eyes and nose,
but it is something that if you do not do well, it jumps out
and ruins your model. We will address the ear carefully in
detail.
Step 47: Create the main loop of the ear. Just as how
we did the nose, the ear can also be modeled
by first laying out the primary structures using
poly loops. Extrude from the back of the ear,
and then start building the loops from there.
There is a color-coded version of the ear loops in
Figure 7.32.
Step 48: Fill the ear. We can use the bridge and
extrude command to fill in the gaps between
the loops; don’t forget to leave a hole open to
extrude out the ear hole (Figure 7.33).
Step 49: Connect the ear. Keep bridging and
extruding faces to connect the ear to the face
264
Character Modeling
Neck
Step 50: Fill the bottom of the head. There are many
lines coming down from the head. However, we
do not want that much happening on the neck.
Redirecting these edge flows to turn to the center
and meet on the other side is a good way of
getting rid of them altogether (Figure 7.35).
Step 51: Extrude the neck. We chose to make the
neck as simple as possible because the turtleneck
collar is covering it. All we do is to extrude from
the bottom of the neck hole to the base of the
neck, and add extra loops in the middle to match
the shape of the concept (Figure 7.36).
265
Creating Games with Unity, Substance Painter, & Maya
FIGURE 7.35 Redirect the line of the face loop to the center and fill the bottom of
the head.
266
Character Modeling
Internal Structures
Step 52: Nostrils internals. Select the loop of the hole
of the nostrils and extrude up and inwards a little
bit; do it two more times so that the hole looks
extended all the way, and make sure the end is
not visible (Figure 7.37).
Step 53: Mouth internals. The mouth Internal is the
same topology as the nostrils but needs more
loops and inflation of the space inside. Select
Ellen_body_geo, press Ctrl + 1 to isolate it. Then
select the edge loop of the seam between the
lips, extrude inwards, and then expand out.
Make sure that there is space for the teeth. Keep
Extruding more until the oval mouth internal
cavity is constructed (Figure 7.38).
267
Creating Games with Unity, Substance Painter, & Maya
Body
Step 54: Create the center loop of the torso. Extrude
from the front bottom of the neck; keep
extruding until the geometry wraps around the
contour of the right view. Merge to the back of
the neck (Figure 7.39).
Step 55: Chest. Create loops around the chest and
the armhole, then bridge a loop from the neck
to the armhole to mark the range of the chest.
Fill the hole of the chest; use the Multi-Cut tool to
fill in the missing topology; add extra lines if the
polycount does not work. Use the sculpting tool
to smooth and refine the shape after getting the
topology done (Figure 7.40).
268
Character Modeling
Step 56: Fill the back. Using the same method of Step
55, we can fill the back of the body (Figure 7.41).
Step 57: Fill the torso. Using the same method of Step
55. We can fill the waist (Figure 7.42).
Step 58: Tweak the flow of the pelvis. Extrude out
a loop from the bottom hole of the torso, and
tweak the shape so that there is a loop around
to represent the upper edge of the pelvis
(Figure 7.43).
269
Creating Games with Unity, Substance Painter, & Maya
Step 59: Loop of the leg hole. Create a loop of the leg
and fill the gap between the pelvis loop to the leg
loop (Figure 7.44).
Step 60: Create the leg. Extrude from the leg hole to
make the leg. We can use a very simple cylinder-
like topology to represent it; keep in mind that
at least three loops are needed to bend the knee
and ankle properly (Figure 7.45).
270
Character Modeling
271
Creating Games with Unity, Substance Painter, & Maya
272
Character Modeling
273
Creating Games with Unity, Substance Painter, & Maya
Hands
Step 65: Palm. Extrude from the wrist to create the
palm; add a few loops to define the size change
of the palm (Figure 7.50).
Step 66: Thumb. Add one more loop to mark out the
base of the thumb and then extrude the faces out
to create the first segment of the thumb. Go to
Edit->Circularize to make the extruded face more
rounded, keep extruding, adding edge loop, and
tweaking to finish the thumb (Figure 7.51).
Step 67: Thumb Tip Topology. Delete all the lines the
tip of the thumb has, and use the Multi-Cut tool
to create a new topology like Figure 7.52. Make
sure that you tweak the shape afterward.
274
Character Modeling
275
Creating Games with Unity, Substance Painter, & Maya
Step 70: Add the finger loops. Add more loops to the
finger; at least three loops are needed for the
bending of each segment. Tweak the shape after
adding new loops (Figure 7.55).
276
Character Modeling
FIGURE 7.56 Duplicate the index finger for the other three fingers and arrange them
properly.
277
Creating Games with Unity, Substance Painter, & Maya
278
Character Modeling
FIGURE 7.59 Use the Muti-Cut tool to fill the missing topology.
279
Creating Games with Unity, Substance Painter, & Maya
280
Character Modeling
Hairs
Step 80: Hair Sculpt. Create a cube, move, and scale
it to roughly the location and size of the hair.
Smooth it four times (Mesh->Smooth), so we
get many polygons to work with. It may shrink
after smoothing, so scale it up again. Go to
the Sculpting shelf, pick the grab tool to sculpt
the shape of the hair. We only care about the
shape of the hair for now. We can give it proper
topology later (Figure 7.65).
Step 81: Auto re-topologize the hair. Select the
hair, choose Mesh->Retopologize. Maya now
automatically creates a topology for us. After the
retopology is done, more tweaks can be applied
to make the shape of the hair better.
Step 82: Add hair detail. Smooth the hair twice, and
now you can use all the sculpting tools to tweak
281
Creating Games with Unity, Substance Painter, & Maya
282
Character Modeling
283
Creating Games with Unity, Substance Painter, & Maya
284
Character Modeling
285
Creating Games with Unity, Substance Painter, & Maya
286
Character Modeling
287
Creating Games with Unity, Substance Painter, & Maya
Select the edges of the upper and lower rim of the model,
hold down the Shift + right mouse button, and choose
Bevel Edge. In the pop-up menu, reduce the Fraction
attribute to make the bevel smaller. Fix the N-gon
generated by the bevel command (Figure 7.77).
288
Character Modeling
289
Creating Games with Unity, Substance Painter, & Maya
290
Character Modeling
291
Creating Games with Unity, Substance Painter, & Maya
Weapon
Step 102: Create the base shape of the gun. Create a
cube, name it Ellen_gun_geo, scale it down on its
X-axis to make it narrower, and extrude from its
front, back, and bottom faces to create the slide
and handle. Keep adding loops and extruding to
292
Character Modeling
FIGURE 7.86 The process to create the base shape of the gun.
293
Creating Games with Unity, Substance Painter, & Maya
294
Character Modeling
Final Clean Up
Step 105: Delete hidden geometry. Duplicate the
Ellen_body_geo, name it Ellen_full_body_ref,
and press Ctrl + H to hide it. Select Ellen_body_
geo, select the faces that are hidden under the
garments, and delete them (Figure 7.89).
Why?
We have a copy of the full body and hid it as a backup
in case something needs to be changed or added. We
rely on the body to add all the garments and props. For
rigging, it is easier to bind the joints with a full-body,
do the skin weighting, and copy the weight over to the
garments.
FIGURE 7.89 Delete the faces that are hidden under the clothing.
295
Creating Games with Unity, Substance Painter, & Maya
296
Character Modeling
Conclusion
We made it! We have a character that is ready to go for UV
texturing, rigging, and animation; the polycount is 29,250
Tris, a little lesser than our prediction. The whole character
is designed and modeled in a week. We have used many
techniques. However, there are far more areas of character
modeling we have not touched, like ZBrush sculpting and
Marvelous Designer, to name a few. If you ever want to
have more advanced knowledge on character modeling,
ZBrush is the next to jump in, and it is a super fun
software. Feel free to stay here and do more tweaking of
the shape of the character before moving on. It is critical
to have a good-looking character with proper topology
for rigging and animation. The final model is shown in
Figure 7.91.
297
CHAPTER 8
UV Mapping
299
Creating Games with Unity, Substance Painter, & Maya
UV Mapping
UV mapping algorithm has been improved through
the years; so, all artists need to do is to define the seam
properly and lay out the UV the efficient way. There
are other tools like Unfold 3D that are dedicated for UV
Mapping, but Maya’s UV tools are already amazingly good.
So, we will stick with Maya for the ease of not having to
move to a different package.
300
UV Mapping
FIGURE 8.2 Overlapping faces results in strange edge flows in smooth preview.
301
Creating Games with Unity, Substance Painter, & Maya
FIGURE 8.3 Potential topology errors that could happen to the middle of the model.
Why?
Topology error occurs all the time, even for industry
veterans. It’s important to fix them before moving on to
the next steps to avoid having to redo things like rigging,
UV, and more.
Body UV
Step 7: Setup workspace. Go to the upper right
corner of the UI, and under workspace, select UV
Editing. Move the cursor to the UV editor, press
302
UV Mapping
303
Creating Games with Unity, Substance Painter, & Maya
304
UV Mapping
Step 11: Cut the jaw and neck. Cut the loops under
the jawline and the back of the neck (Figure 8.7).
Step 12: Cut arms and hands. Project the UV of Ellen_
hands_geo the same way using UV->Planar. The
arm is basically a cylinder. Go to UV->3D Cut and
Sew UV Tool and double-click the bottom loop of
the arm to cut it open. Cut the middle line on the
side of the fingers to separate them into up and
bottom shells (Figure 8.8).
Step 13: Unfold and optimized the UVs. Turn off
symmetry, go to object mode, and select both
Ellen_hands_geo and Ellen_head_geo. In the
UV Editor, hold down the right mouse button
and choose UV, and drag-select all the UV points.
Hold down the Shift + right mouse button, go to
unfold->unfold□, and set the Method to Unfold
3D; press the Apply and Close buttons. The shells
should now be unfolded nicely.
Hold down the Shift + right mouse
button, go to Optimize□. Under the Optimize
Options section, set the Iterations setting
to 30, press Apply and Close (Figure 8.9).
You can do optimize many times to reduce
stretching further.
305
Creating Games with Unity, Substance Painter, & Maya
306
UV Mapping
Step 14: Layout UV. With all the UVs selected in the
UV Editor, hold down the Shift + right mouse
button, go Layout->Layout□. Under the Pack
Settings section, change Packing Resolution
to 4096; under Layout Settings section, set
Texture Map Size to 4096, Shell Padding to 30,
and Tile Padding to 30. Click on Apply. The
UVs are now arranged for us automatically
(Figure 8.10).
Step 15: Manually adjust the UV layout. The UV laid
out is technically fine but could be enhanced. We
can see some unutilized space and some tilted
shells that could be more straight. Double-click
any UV point of a UV shell to select the entire
shell; in the UV editor menu, select Modify->
Orient shells to make it straight. Rotate the shell
307
Creating Games with Unity, Substance Painter, & Maya
Why?
We want to squeeze all the possible performance and quality
out. That means even a little better UV space utilization is a
win; that’s why manually adjusting the UV is necessary.
Eye UV
Step 16: Eyeball UV Mapping. Select Ellen_l_eye_
geo, go to UV->Planar to project it to the UV
Space. Go to UV->3D Cut and Sew UV Tool, and
double-click to cut the vertical loop in the middle
of the eyeball. Select all the UV vertices, hold the
Shift + right mouse button; go Unfold->Unfold.
Double-click any UV point of the front shell to
select the entire shell, hold the Shift + right mouse
button, go Layout->Layout. Scale the shell down
just a little bit to avoid it touching the edge.
Select the back shell, scale it down, and move it
to any corner (Figure 8.12).
308
UV Mapping
Why?
We will never see the back of the eyeball, so there is no
point in wasting UV space; that’s why we scaled it down
and moved it to a corner.
Hair UV
Step 18: Hair UV. Project the hair UV to the UV Editor
the same way we did for the body and eyeball.
Go to 3D Cut and Sew UV Tool, find a relatively
hidden loop to cut the frontal hair clump open;
it is also helpful to cut the back half of the hair
open. With all UV vertices of the hair selected, do
309
Creating Games with Unity, Substance Painter, & Maya
Why?
We have scaled the eyebrow and eyelashes up, and this
will result in uneven UV distribution. However, it gives us
more resolution for the eyebrow and eyelashes. It is going
to help us to add more detail to them if necessary.
310
UV Mapping
311
Creating Games with Unity, Substance Painter, & Maya
FIGURE 8.16 Combine the UVs of the eyebrows, eyelashes, and the hair.
Garment UV
Step 22: Project the rest. Select the rest of the models
together, go to UV->Planner to project them all
at once (Figure 8.17).
Step 23: Cut the sweater. Select Ellen_sweater_geo;
use the 3D Cut and Sew UV Tool to cut the
sweater. Cut the two arms, two rolled back
sleeves, and the collar out; these parts are
basically cylinders. Just find a relatively hidden
loop to cut them open. Cut the rest of the body to
front and back pieces in the middle (Figure 8.18).
Step 24: Cut the outfit. Select Ellen_outfit_geo, Cut
the model to front and back pieces through the
middle on the outside and between the legs. Cut
through the loop of the waist where we have
the separation of the color of the pants and the
upper part (Figure 8.19).
Step 25: Cut the UVs of the belt. Select Ellen_belt_
geo, cut the loop on the inner side of the bottom
of the belt, cut the center vertical loop on the
back, and cut the buckle out (Figure 8.20).
Step 26: Cut the pockets. The pockets are basically a
cube; if you look at the default UV of a cube, that
is going to be exactly how we cut the pockets,
312
UV Mapping
313
Creating Games with Unity, Substance Painter, & Maya
314
UV Mapping
315
Creating Games with Unity, Substance Painter, & Maya
316
UV Mapping
FIGURE 8.23 All the cutting choices of the rest of the models.
FIGURE 8.24 Unfold, optimize, and lay out all the UVs.
317
Creating Games with Unity, Substance Painter, & Maya
FIGURE 8.25 Separate the UVs and put them into different UV tiles.
Why?
We have purposely arranged the UV to the four tiles to
get more resolution. The gloves, the watch, and the gun
also have higher resolution because they are close to the
viewer in the game. We can check the relative resolution
by checking on the Checker Map option in the Textures
menu in the UV Editor. The smaller the checker pattern is,
the higher the resolution.
318
UV Mapping
Why?
There are seven materials created for the character; it is a
little heavy to use, but we are going to get good quality.
How many materials are used is based on the engine and
the target platform. For our desktop game, we can spoil
ourselves a little.
Conclusion
We have now finished the UV Mapping process. It takes
some time but is often not considered difficult to do.
All we did here is to project, cut the seams open, unfold,
and layout. However, the arrangement and the packing
of these UV pieces require some serious thinking. UV
319
Creating Games with Unity, Substance Painter, & Maya
320
CHAPTER 9
Character Texture
Painting
321
Creating Games with Unity, Substance Painter, & Maya
322
Character Texture Painting
Why?
The eyeballs can look around, baking an ambient
occlusion map and other maps would not make much
sense. There are other moving parts like the mouth that
we should, in theory, open when baking so that no dark
ambient occlusion is baked on the part where the upper
and lower lips meet.
Skin Texturing
Step 5: Basic skin color. Hold down Ctrl + Alt and
right-click on the face to switch to Body_Mtl. Go
to the LAYERS panel. Click on the bucket icon
to add a fill layer. Double-click on the name of
the Fill layer 1 to rename it as Skin_Base. Go the
PROPERTIES panel, change the base color to a
basic skin color, and drag the Roughness slider
higher to make it less shiny (Figure 9.2).
Step 6: Skin red tint base. Create another fill layer,
rename it to Red_Tint, change the color to a pure
red color. Under the MATERIAL section, click on
height, rough, metal, and nrm to turn off these
channels. Right-click on the Red_Tint layer and
select Add black mask. Right-click on the black
mask and select add fill. On the right side of
the fill, set the visibility percentage to 80. In the
PROPERTIES panel, click on the grayscale, type
in clouds in the search bar and click Clouds 1, set
the Projection to Tri-planar projection, and set
the Scale setting to 16 (Figure 9.3).
Why?
It may appear to be crazy after Step 6. However, we are
going to layer multiple textures together to get a proper
final skin result. And we can get very rich color variation
by doing it this way. Tri-planar projection projects the
texture from the front, side, and top views of the model;
this enables the avoidance of any seams.
323
Creating Games with Unity, Substance Painter, & Maya
324
Character Texture Painting
325
Creating Games with Unity, Substance Painter, & Maya
326
Character Texture Painting
327
Creating Games with Unity, Substance Painter, & Maya
Why?
It seems a huge waste of time doing all the blending and
eventually blurring it. However, it can make a substantial
difference with all the noisy blendings. It is also because
of the stylized art style that we blurred our texture quite a
bit to make it look clean.
328
Character Texture Painting
329
Creating Games with Unity, Substance Painter, & Maya
330
Character Texture Painting
FIGURE 9.12 Draw lines to mimic the edge of the various clumps of the hair.
Hair
Step 15: Hair base color. Hold down Ctrl + right
mouse button on the hair to switch to the Hair_
mtl. Add a new fill layer, and name the new layer
Hair_Base. Set the Base Color of Hair_Base to a
dark red and set the roughness to 0.45.
Step 16: Hair dark color. Copy and paste Hair_Base
and name the duplicate as Hair_bottom.
Make the color darker and change its Height to
−0.5. Right-click on the layer and give it a black
mask. Add a paint layer to the mask. Press the D
button to toggle the steady stroke; steady stroke
makes your stroke more fluid. Start drawing lines
to mimic the edge of the various clumps on the
hair (Figure 9.12).
331
Creating Games with Unity, Substance Painter, & Maya
FIGURE 9.14 Add more layers to refine the curvature of the hair clumps.
Why?
We used three layers to add the height information and
utilized different blur values to achieve good control
332
Character Texture Painting
FIGURE 9.15 Add bright tint to the high ground of the hair clumps.
Eye
Step 20: Eye white. Switch to the Eye_mtl, create a
new fill layer, and name it Eye_White. Change
the color of the layer to a red color, give it a black
333
Creating Games with Unity, Substance Painter, & Maya
Why?
We chose polygon 2 as the mask instead of painting
it ourselves with a brush. Using polygon 2 makes it
more flexible and cleaner; this is also something we call
procedural texturing.
334
Character Texture Painting
FIGURE 9.16 Create a folder for the iris and add a mask to it.
335
Creating Games with Unity, Substance Painter, & Maya
Why?
In theory, the darkness of the upper portion of the iris is
caused by shading. The brighter color on the bottom part
336
Character Texture Painting
337
Creating Games with Unity, Substance Painter, & Maya
338
Character Texture Painting
FIGURE 9.21 Blur the brighter color at the bottom of the iris.
339
Creating Games with Unity, Substance Painter, & Maya
Upper Body
Step 29: Sweater base. Switch to the Upper_body_
mtl, add a new fill layer and name it Sweater_
Base, change its color to a dark gray, and
roughness to 0.8. Press Ctrl + G to group it under
a folder; name the folder Sweater. Add a black
mask to the folder and give the mask a paint
layer. Hit the number 4 button on the keyboard
to toggle the polygon fill tool; in the PROPERTIES
panel, click on the checker box button to switch
to UV shell selection mode. Change the Color to
1, go to the 2D view, and click on the UVs of the
sweater (Figure 9.25). The mask should now be
white on the sweater.
340
Character Texture Painting
FIGURE 9.23 Make the contour of the iris block the height of the fibers.
341
Creating Games with Unity, Substance Painter, & Maya
342
Character Texture Painting
FIGURE 9.27 Fix the direction of the patterns with new layers.
343
Creating Games with Unity, Substance Painter, & Maya
344
Character Texture Painting
345
Creating Games with Unity, Substance Painter, & Maya
Why?
It is difficult to paint clean lines, so we use the Shift-click
trick to draw straight lines instead of trying to create a
fluid arc line.
346
Character Texture Painting
347
Creating Games with Unity, Substance Painter, & Maya
FIGURE 9.33 Add circular patterns to the side patch of the outfit.
Pants
Step 38: Pants base color. Switch to the Lower_body_
mtl, go to SHELF, click on the Materials section,
search for Fabric Baseball Hat, and drag it to the
layers. Name the new layer Pants_Base, change
the Scale of the layer to 3, and tweak the rotation
value so that the direction of the lines in the
pattern becomes vertical. Finally, change the color
to a darker grayed out blue color (Figure 9.34).
Step 39: Pants gradient. Duplicate Pants_Base,
name the duplication Pants_Darker, and make
the color of Pants_Darker darker and bluer.
Give the layer a black mask, add a generator
to the mask, in the PROPERTIES panel, and
change the generator to Mask Editor. In the
PORPERTIES panel, set the Curvature Opacity
to 0 and the Position Gradient Opacity to 1.
Open the Position Gradient section, turn on
the Invert, and set the contrast to 0.7. Tweak
the Balance value so that the transition of the
brightness of the color starts around the knee
(Figure 9.35).
348
Character Texture Painting
349
Creating Games with Unity, Substance Painter, & Maya
FIGURE 9.36 Create the high ground and the seam of the flipper of the pants.
350
Character Texture Painting
351
Creating Games with Unity, Substance Painter, & Maya
352
Character Texture Painting
353
Creating Games with Unity, Substance Painter, & Maya
FIGURE 9.43 Add the Rubber Dry material to the bottom of the boots.
Gloves
Step 49: Glove Base. Switch to the Glove_and_watch_
mtl and drag Leather Stylized into the layer stack.
The result should look like Figure 9.44.
354
Character Texture Painting
355
Creating Games with Unity, Substance Painter, & Maya
356
Character Texture Painting
FIGURE 9.48 New baking result with the smoothed mesh as the high-resolution
model.
357
Creating Games with Unity, Substance Painter, & Maya
FIGURE 9.49 New leather material appearance with the new curvature map.
358
Character Texture Painting
359
Creating Games with Unity, Substance Painter, & Maya
FIGURE 9.52 Use anchor point to create edge wear for the heightmap we painted.
360
Character Texture Painting
FIGURE 9.53 Hand paint more details to the edge wear of the glove.
Watch
Step 54: Add a basic material to the watch. Go to the
shelf, drag the Plastic Fake Leather material on
top of the Leather Stylized. Give it a black mask
with a paint layer, press the number 4 button
to use Poly Fill tool, and change the mode of
the Poly Fill tool to UV shell mode. Set the color
to white, and click on the watch to assign the
material to the watch (Figure 9.54).
Step 55: Add material to the screen of the watch.
Create a new fill layer and name it Watch_
Monitor. Change the Base Color of the layer to a
dark gray, height to −0.35, roughness to 0.01, and
the blend mode of the Height channel to normal.
Give it a black mask and use the Poly Fill tool to
make it appear only on the screen of the watch
(Figure 9.55).
Step 56: Add extra height to the watch. Create a new
fill layer, name it Watch_Extra_Height, and drag
the Height down to −1. Add a black mask with a
paint layer and start to paint extra detail on the
watch. After painting, drag both Watch_Monitor
and Watch_Extra_Height to Plastic Fake Leather
and rename the folder Watch (Figure 9.56).
361
Creating Games with Unity, Substance Painter, & Maya
FIGURE 9.54 Use the Plastic Fake Leather material as the base material for the watch.
362
Character Texture Painting
Gun
Step 57: Gun rebake. Switch to the Gun model and
press Alt + Q to isolate the gun. The portion inside
of the holster is darker due to the baked Ambient
Occlusion. Open Maya and load the model in
there, grab the Ellen_gun_geo, go to File->Export
Selection, use the FBX format, and export with
the name Gun_High. Back to Substance Painter,
go to TEXTURE SET SETTINGS, and click Base
Mesh Maps. Check off Use Low Poly Mesh as High
Poly Mesh, load Gun_High in the High-Definition
Meshes, and click on Bake Gun_mtl Mesh Maps
to bake the mesh maps for the gun again.
Step 58: Texture the Gun. The Method we use to
texture the gun is the same we used to texture
our environment modules. Go ahead and finish
texturing it; Figure 9.57 shows our result.
Other Details
Step 59: Chest Logo. Switch back to Upper_body_mtl
and create a new fill layer above Fabric UCP.
Name the new layer Chest_Logo, change its
363
Creating Games with Unity, Substance Painter, & Maya
364
Character Texture Painting
Export Textures
Step 61: Export Textures. Go to File->Export Textures.
In the pop-up Export Document settings
window, go to CONFIGURATION and choose
the same configuration we did in Chapter 4.
Go back to EXPORT, change the format from png
to targa, click on the directory, and change it
to the sourceimages folder of the Maya project.
Add a new folder there and name the folder
365
Creating Games with Unity, Substance Painter, & Maya
366
Character Texture Painting
Why?
Bake pivot calculates the location and rotation of the pivot
relative to the origin and overrides the translation values
with that. We can use it to get the rotation of a tilted model
back, even if we have done a freeze transformation on it.
Conclusion
That’s it, we have finished our character texturing! Overall,
with Substance Painter, the texturing process should be
a joyful one. With smart masks, generators, height map
painting, and PBR workflow, we can get many things
done. Be aware that we have seven texture sets, or
materials, each with 2k images to achieve this crisp, high-
resolution result. It is a pretty ambitious setup and would
not be recommended for low-performance platforms.
However, we could spoil ourselves on a PC game like what
we are doing.
367
CHAPTER 10
Rigging
369
Creating Games with Unity, Substance Painter, & Maya
Joint Behavior
Create a new Maya file and go to the side view. In the
rigging module, click Skeleton, create joints. Click in
the side view once, then move your cursor to a new
area above and click again. Do this one final time and
press Enter. We now have a three-joint chain created
(Figure 10.1).
370
Rigging
371
Creating Games with Unity, Substance Painter, & Maya
Why?
Referencing is an industry-standard process. We reference
in characters, environment, and rigs into scenes so that
should the characters, environments, or rigs will be
updated. The file that we are working on automatically
grabs those updates. This allows us to make sure we are
working on the most up-to-date models and rigs.
Why?
By creating our joints in the side view, the joints will
be created directly in the center of the character. This
is especially important because we’ll be mirroring our
left arm and left leg joint to the right side to save some
time.
372
Rigging
373
Creating Games with Unity, Substance Painter, & Maya
Why?
This is the cleanest way of setting up a rig for animation.
By keeping the rotation values at 0, animators can easily
reset the joints to their original position by entering values
of 0 in the rotation rather than some odd number.
374
Rigging
375
Creating Games with Unity, Substance Painter, & Maya
FIGURE 10.5 Before moving on, make sure there are no non-zero rotation values
for the joints.
Why?
Using joint orient allows us to rotate the joints while
keeping the original joint orientation clean.
Step 12: Position the arm joints to the right spot. First,
move the clavicle if it is too far in the front or in
the back. Next, select the left_shoulder joint and
376
Rigging
377
Creating Games with Unity, Substance Painter, & Maya
378
Rigging
379
Creating Games with Unity, Substance Painter, & Maya
Step 17: Name the finger joints. Let’s now label these
joints left_hand_index_01, left_hand_index_02,
left_hand_index_03, and left_hand_index_04
(Figure 10.12).
It’s possible that our joint orientations
are a little skewed after creation. Let’s go
and zero out the values of the joint orient of
left_hand_index_02, left_hand_index03,
and left_hand_index_04.
Why?
Upon doing this, we now have a clean structure wherein
the fingers are all straight. Now we can get the orientation
correct by changing the joint orientation values in the
attribute editor the same way we did for the arm joints.
Now that we got that all cleared up and ready to go, let’s
duplicate and use that same joint setup for the rest of the
fingers.
380
Rigging
381
Creating Games with Unity, Substance Painter, & Maya
382
Rigging
Step 21: Create the leg joints. In the side view, create
a new joint at the center of the hip area and
name it left_thigh. Create another joint at the
knee and then the ankle; name them accordingly
(Figure 10.16).
383
Creating Games with Unity, Substance Painter, & Maya
Step 22: Create the foot joints. Add two more joints
for the ball of the foot and the toe, name them,
and parent the ball joint to the ankle joint after
creation (Figure 10.17).
Once our structure is created, we need
to go to the front view of the character and
move left_thigh to match the leg joints to
the left leg and parent it to the hip joint
(Figure 10.18).
Step 23: Mirror the leg joints. The next step would be
to mirror this leg the same way we mirrored the
clavicle.
Step 24: Parent the hip joints underneath the hip
joint.
384
Rigging
FIGURE 10.17 Final joint chain for the left leg and foot.
385
Creating Games with Unity, Substance Painter, & Maya
FIGURE 10.18 Match the leg joint to the model and parent it to the hip.
386
Rigging
387
Creating Games with Unity, Substance Painter, & Maya
Why?
We’ll be animating with the NURBS curves later on, and we
need those to not have any values on them to make life
easier for the animators. By keeping the values empty, we
can easily reset the controller back to default by entering
0 in the values.
388
Rigging
Why?
We could easily scale the controller up, but that introduces
scale values in the Channel Box, which will cause
problems for animation and rigging later on. Always
remember, the Translate X, Y, Z and Rotate X, Y, Z values of
your controller should remain 0, while the Scale X, Y, and Z
values should remain 1.
Step 32: Create the controller for the left ball joint.
Repeat the same process given in Steps 29–31 for
the left_ball joint.
389
Creating Games with Unity, Substance Painter, & Maya
390
Rigging
391
Creating Games with Unity, Substance Painter, & Maya
392
Rigging
393
Creating Games with Unity, Substance Painter, & Maya
FIGURE 10.26 Paint the weighting for the head and the neck.
394
Rigging
395
Creating Games with Unity, Substance Painter, & Maya
396
Rigging
397
Creating Games with Unity, Substance Painter, & Maya
398
Rigging
399
Creating Games with Unity, Substance Painter, & Maya
400
Rigging
401
Creating Games with Unity, Substance Painter, & Maya
Constrains
After you apply constrains to objects, the second one
in the selection starts to follow the first one in the
selection. Orient constraint makes the object follow this
rotation only. Go to the constrain menu, and you can
still see Parent and Point. Parent constraint makes the
object follow both the translation and the rotation. Point
constraint makes the object follow the translation only.
402
Rigging
IK Arm Setup
Now let’ setup the IK arm controls.
403
Creating Games with Unity, Substance Painter, & Maya
404
Rigging
405
Creating Games with Unity, Substance Painter, & Maya
406
Rigging
FIGURE 10.40 Left clavicle and shoulder joint setup and hierarchy.
407
Creating Games with Unity, Substance Painter, & Maya
408
Rigging
409
Creating Games with Unity, Substance Painter, & Maya
Gun Joint
We now need to add one last joint that will be used for the
weapon in the game.
Final Hierarchy
Now that we have all the controls created, we just need
to clean them up in the outliner and make sure they’re
placed in the correct order and under the proper groups.
Conclusion
We have finished our rig, but bear in mind that this setup
is the bare minimum of rigging; we ripped off everything
we could to keep rigging simple for you. However, if you
want to have more advanced rigs, there are plenty of
auto rigs out there. Plug-ins like Advanced Skeleton and
Rapid Rigs can make all the controls for you in a matter
of minutes. Maya has its own auto rig as well, located at
Control->Create Control Rig.
410
Rigging
411
CHAPTER 11
413
Creating Games with Unity, Substance Painter, & Maya
animations, but once those are set up, breathing life into
our character should be straightforward. Before moving
on, if you feel like speeding up the workflow, you can
jump to the next chapter where the second half shows
how to use motion captured data as our animation
instead of doing it manually.
Why?
When you start animating and maybe realize that you
need to make model or rigging adjustments, you can
jump into the original rig file, Ellen_rig, and make those
changes. When you return to your animation file with the
referenced rig, those adjustments will be reflected on
the model and/or rig, and your animation should still be
intact. If you do not see those changes immediately, go
to File>Reference Editor, right click on the rig name in the
newly appeared window, and choose Reload Reference to
bring in those changes into your animation file.
414
FPS Animation in Maya
Save Files
All the animations for each weapon set will be housed in
their own Maya file. When you save this Maya file, name it
Ellen_gun_animations to distinguish it from other files.
Display Layers
Seeing your character without any obstructions is
important while you animate. Display layers can be used
to hide certain aspects of the model or rig when they are
not needed, while also removing the need to dig through
the Outliner every single time you want to hide those
character parts.
415
Creating Games with Unity, Substance Painter, & Maya
Why?
During the animation process, you will want to only move
the controls created during the rigging process, not the
character geometry. By putting Ellen’s upper body, arms,
and weapon geometry on their own display layers with
the referenced option active, you will not have to worry
about setting stray keyframes beyond the controls.
Figure 11.1 shows an example of the various display layers
created so far.
416
FPS Animation in Maya
417
Creating Games with Unity, Substance Painter, & Maya
Camera Configuration
Step 5: Select the Front/Persp quick layout button,
located right above the Outliner button, to
bring up two viewports on your screen. We will
create a dedicated FPS camera in the left-hand
viewport by going to Panels>Perspective>New.
Name it FPS_Cam. In that same viewport, turn
on the resolution gate by clicking on the icon
seen in Figure 11.3. Also click on the gate mask
icon, which is to the right of the resolution gate
icon, so that a light grey, shaded area will appear
FIGURE 11.3 Resolution gate icon. around the gate.
Step 6: On the right-hand-side viewport, we will
move FPS_Cam so that it mimics the player
character’s line of sight. If you do not see a
floating green camera, check if camera visibility
is on by going to Show>Cameras in the Viewport
menu bar. Grab FPS_Cam and move it so that is
near Ellen’s eyes (Figure 11.4). You may turn on
the visibility of the RestofBodyMesh display layer
temporarily so you can position the camera with
Ellen’s head geometry on.
Why?
This viewport setup will allow you to see the FPS camera
view and your working area at the same time. Since the
resolution gate and gate masks are visible on the left-
hand side, you will be able to focus on what the player
will see in the game. Grabbing controls will be easier in
the right-hand-side viewport since you can move freely
around the scene.
418
FPS Animation in Maya
419
Creating Games with Unity, Substance Painter, & Maya
Why?
In FPS games, a reticle is a small icon, like a crosshair
or dot, in the center of the screen that is used to assist
the player with aiming. There will be a different reticle
created in the game engine, but our locator reticle will
still be useful. We can reference it while posing our
character and make sure that the weapon is pointed
towards the reticle.
Game Animations
We are close to being able to animate full speed ahead.
At this point, we can start crafting our first pose. Game
characters have a set of animations that will play in
the game depending on the circumstances. One of
the most important animations will be the idle. An
idle animation will be playing when the player has not
input any commands. It is meant to keep the character
alive even though they are not performing any specific
movements. The idle is the first to be created in a set
because it will serve as the returning point for most
animations. When Ellen is done walking or has finished
firing her gun, she will return to the idle animation.
420
FPS Animation in Maya
FIGURE 11.6 Right clicking channel attributes to lock the locator’s movement.
The only time Ellen will not return to idle is after she is
caught by the security cameras and the game is over.
The other animations that Ellen will need are attack,
walk, “got caught”, and reload.
Creating a Pose
Animation is a time-based art form, and the illusion of
movement is created when a series of poses are played
one after another. When we create a pose, we will need
to tell Maya that we want it to be played at a specific time.
The Time Slider at the bottom of the screen will be where
421
Creating Games with Unity, Substance Painter, & Maya
422
FPS Animation in Maya
423
Creating Games with Unity, Substance Painter, & Maya
424
FPS Animation in Maya
425
Creating Games with Unity, Substance Painter, & Maya
426
FPS Animation in Maya
Frame Rate
Animations created for film and television are generally
created at 24 frames per second. Standard playback rates
for video games are 30 and 60 fps. Always double check
the frame rate in Maya before starting an animation.
Idle Animation
We will create a breathing idle animation for Ellen. It is
possible to create idle breakers that are animations that
still play when the player has not input any commands,
and they generally show a bit more personality. Our main
idle animation will be a simple inhale and exhale with a
touch of weight shifting.
427
Creating Games with Unity, Substance Painter, & Maya
428
FPS Animation in Maya
Graph Editor
Animators must become acquainted with the Graph Editor
to finetune their work. All keyframes are represented on
a graph as plotted points that can be adjusted, and the
interpolation between each keyframe is represented
as curves. With a basic understanding of curves, the
Graph Editor can be used to create quick ease-in’s and
ease-out’s.
429
Creating Games with Unity, Substance Painter, & Maya
Why?
Understanding what the curve shapes represent is more
important than just simply copying. The curve shape from
frames 0 to 13 is an ease-out. The gentle slope represents
small movement over a long period of time. We know
that frames 13–25 will be faster due to the steep slope
that showcases a large value change over a short period
of time. Frames 25–35 is another ease-in. Ease-in’s and
430
FPS Animation in Maya
Keywords Aside
Timing is the object’s speed, while spacing is how the
object will move from point A to point B. Spacing will
help determine moments of acceleration and moments
of hold.
Attack Animation
The attack animation is up next. The gun firing should
be rapid and impactful. As soon as the player presses the
button to attack an enemy, we want the player to see and
feel an immediate response in the gun. A combination
431
Creating Games with Unity, Substance Painter, & Maya
Step 16: Select all the controls, copy the first frame
of the idle animation, and paste it on frames 200
and 212. Frame 200 will be the start of the attack
animation, and 212 will be the end. On frame
204, create the recoil pose by moving the gun
back closer to Ellen and rotate the gun so that
it is pointing upward. Maya should now show
the initial movement between frames 200 and
204, but it is still too slow. To help show snappy
gunfire, move the gun backwards towards Ellen
on frame 201.
Step 17: Let’s add some final touches to the attack
animation. Set a keyframe on frame 208 for
the main movement control. Open the Graph
Editor and create an ease-in using the newly
added keyframe. Go through all the Translate
and Rotate channels on the left-hand-side bar
to check if there is a moving curve to add an
ease-in. Figures 11.16 and 11.17 are two examples
of how this ease-in could be implemented on
frame 208. If there is a horizontal line instead
of a trending curve, this means that there is
432
FPS Animation in Maya
Walk Animation
A basic walk animation consists of the following main
poses: contact, down, passing, up, and back to contact
pose to repeat the cycle. This animation will be simpler
to create as first-person shooter animation in contrast
to a full-body piece, but we can still move the arms and
weapon in accordance with the main poses.
433
Creating Games with Unity, Substance Painter, & Maya
434
FPS Animation in Maya
FIGURE 11.19 Additional keyframes to give more weight to the passing poses.
Step 22: Select all the controls, copy the idle pose,
and paste it on frame 400. If you are animating
with the two-handed weapon setup, select
leftHand_locator and make sure that it also has
a keyframe at 400. If the locator did not have
any keyframes placed beforehand, you should
notice a new attribute in the Channel Box called
Blend Locatorleftparent 1. On frame 400, Blend
Locatorleftparent 1 should be set to 1. To detach
the left hand from the gun handle, change
Blend Locatorleftparent 1 to 0 on frame 401.
Hide leftHand_locator while you create the “Got
Caught” animation. You can now move ac_l_ik_
drv_wrist independently of gun_CTRL.
435
Creating Games with Unity, Substance Painter, & Maya
Keywords Aside
Depending on the speed of an action, we might need to
add an overshoot pose to give more time to the audience
to take in what just happened. The overshoot will move
past the last pose we just created and will settle into the
last pose more slowly.
436
FPS Animation in Maya
FIGURE 11.21 Motion trail representing the left hand’s path of action.
FIGURE 11.22 Adding more keyframes to round out the motion trail.
437
Creating Games with Unity, Substance Painter, & Maya
Why?
Most living beings move in arcs, while machinery tend
to move in a linear fashion. Exaggerating the arcs of an
object’s motion trail can be a quick way to add a layer of
fluidity to the animation.
Reload Animation
The reload animation will be a culmination of everything
that we have covered, as well as adding one more object
for Ellen to interact with. If the two-handed setup is in use,
the left hand will need to leave the gun handle once more.
The added challenge is that we must get the character
to return to the idle pose, in contrast to the “Got Caught”
animation that did not have to loop. In this animation,
Ellen will first shake the empty magazine out of the gun.
Her left hand will temporarily leave the screen to grab the
new magazine. Once the left hand returns to the player’s
view, Ellen will reload the gun, and the left hand should
return to its original idle pose.
438
FPS Animation in Maya
439
Creating Games with Unity, Substance Painter, & Maya
440
CHAPTER 12
Auto Rigging
441
Creating Games with Unity, Substance Painter, & Maya
442
Auto Rigging
Mixamo
Our goals then in this chapter is to use some external tools
to auto-rig a character and plug some motion-captured
animations into those rigs. Finally we will export those
animations and use them later in the production process
(Chapter 17 to be exact). This chapter will be short and the
process quick thanks for a free-to-use online tool called
Mixamo.
Why?
Since the textures were constructed in Substance Painter –
the textures will be exported from there and reassembled
in Unity. So, we don’t need or want a version of Ellen
443
Creating Games with Unity, Substance Painter, & Maya
Why?
We haven’t changed the FBX format before; why now?
Well, for reasons only known to Adobe at this point,
Mixamo requires FBX 2013 or earlier. If you export using
FBX 2020 (which is what we’ve used up to now), Mixamo
will complain.
444
Auto Rigging
FIGURE 12.2 When exporting for Mixamo, be sure to use FBX 2013.
Why?
There is already a gun on the mesh we’re exporting; why
do we need another. It’s a little tricky to explain at this
point, but the gun is about to become part of a rig, which
means the gun will be controlled by a joint. Later in this
tutorial, we will need the gun in her hand (not on her
thigh), and so having a separate gun not tied to a joint
chain will make things much easier.
445
Creating Games with Unity, Substance Painter, & Maya
FIGURE 12.3 To begin importing EllenEnemy to Mixamo, log in and use the
Characters link.
FIGURE 12.4 Sending the EllenEnemy fbx to Mixamo for processing. Mixamo will process for a second before showing Figure 12.5.
FIGURE 12.5 The imported version of the character. Don’t worry about the materials showing up black. We will be reimporting
textures later.
446
Auto Rigging
FIGURE 12.6 Placing markers to help the Auto-Rigger determine the anatomy of the character.
447
Creating Games with Unity, Substance Painter, & Maya
Why?
EllenEnemy will likely quickly leave her preview space.
And her movements might not make a lot of sense at first.
You can follow her by clicking the little camera icon in
the bottom left of her preview space. What is happening
is that EllenEnemy is running through a whole lot of
animations one right after another with little break in
between. In reality, she’s doing a lot more than we will use
in the scene, but bringing in this whole pack will provide a
lot of different things for this character to do.
448
Auto Rigging
FIGURE 12.9 Be sure to grab all the different FBX files that Mixamo includes as part of the Pistol_Handgun Locomotion Pack.
449
Creating Games with Unity, Substance Painter, & Maya
450
Auto Rigging
FIGURE 12.11 EllenEnemy placed in the scene with a cheater light to see and
understand the shaders.
451
Creating Games with Unity, Substance Painter, & Maya
452
Auto Rigging
Why?
Subsurface Scattering is the ability of some surfaces to
scatter light that penetrates their surface. Think of the
difference between a glass full of white paint and a glass
full of milk. The milk allows light to penetrate the surface
and then diffuses it through its volume. Human skin is
a good example of subsurface scattering and is a great
place to use this material type. The results are subtle
(Figure 12.14 left is Standard and right is Subsurface
Scattering), but important.
FIGURE 12.15 Adjusting the Base Map color tints from the default gray tint to white.
453
Creating Games with Unity, Substance Painter, & Maya
454
Auto Rigging
FIGURE 12.17 Import settings for all the pistol xxx animations. Don’t click Apply yet.
FIGURE 12.18 Assigning EllenEnemyAvatar as the Source avatar for all the animation files.
455
Creating Games with Unity, Substance Painter, & Maya
Why?
This process is a little goofy to set up but has tremendous
power. Now, select any of the pistol animations (pistol
run arc or instance), and in the Inspector, click the
Animation tab. At the bottom of the Inspector, you’ll see
the EllenEnemy character animated to that animation clip
(Figure 12.19). Let’s start a simple situation where Ellen
stands at idle.
Why?
Lots happening here. All the Mixamo animations come in
named “mixamo.com.” Useless. Renaming them as we go
will make them easier to work with. The idle needs to loop
(thus clicking the Loop Time). Baking the Root Transform
Rotation using the Original rotation will make sure that
the animations are indeed facing forward. We will do
similar things to this for every animation before we’re
done.
456
Auto Rigging
FIGURE 12.19 By having the animations inherit the avatar from EllenEnemy, all the
animations now have a rig and geometry to be animated.
457
Creating Games with Unity, Substance Painter, & Maya
FIGURE 12.20 Assigning the new Animator Controller EllenEnemyController to control EllenEnemy.
FIGURE 12.21 Preparing pistol idle for use in scene with renaming and looping.
458
Auto Rigging
FIGURE 12.23 EllenEnemy shifting to her idle animation. Obviously, we need to fix
that gun.
Why?
We need to get that gun off her thigh and into her hand.
To do this, we’ll actually bring in another copy of the gun
and hide the one in the holster. The reason for this is that
459
Creating Games with Unity, Substance Painter, & Maya
The process will be a quick three steps: hide the gun in the
holster, export/import the gun from Maya, and position it
as a child of the joints in her hand.
460
Auto Rigging
FIGURE 12.25 Making Ellen_Gun a child of the right hand joint so where the hand
goes, the gun goes.
461
Creating Games with Unity, Substance Painter, & Maya
462
Auto Rigging
Why?
The pack we downloaded in the earlier step has a huge
collection of movement animations but does not include
one of the character actually shooting the gun. For our
design, the character is going to stop when they shoot
their weapon; so we need to track down an animation that
will show this.
FIGURE 12.28 Exporting just the animation. No need for skin this time (we’ve
already imported that).
463
Creating Games with Unity, Substance Painter, & Maya
Conclusion
Unfortunately, here is where we need to leave EllenEnemy.
No worries though. Later, we’ll spend plenty of time
teaching her to patrol the level, chase the player, and
attack them when they are close enough. But to do that,
we first need to learn more about the Animator and how
to write some code to control it. We’ll start on that in
Chapter 14 and then again spend a lot of time on AI in
Chapter 17.
For now, it’s onto the basics of C#. The fun is just
beginning!
464
CHAPTER 13
Introduction to C#
465
Creating Games with Unity, Substance Painter, & Maya
C#
Ironically, Unity is built in C++ (not C#). However, C++ is
a pain to learn and, for most coders, higher level coding
languages are a much more approachable way to train
a computer to do tasks. C# is the undisputed preferred
language of coding for Unity, and it has generally
deprecated (abandoned) all other previously used
languages, including a variant of JavaScript and a variation
of Python called Boo.
466
Introduction to C#
FIGURE 13.1 Example empty script created in Unity and viewed in Visual Studio.
467
Creating Games with Unity, Substance Painter, & Maya
468
Introduction to C#
FIGURE 13.2 Brackets indicate the start and end of a function or class. Usually they
are vertically aligned, and code contained in the function or class is tabbed one more
level in than the curly bracket.
badguy.transform.position.x;
And with that, let’s get busy building code. There are
lots more important things to talk about (variables
for starters); but let’s explore them as we need them.
469
Creating Games with Unity, Substance Painter, & Maya
The IDE that most folks use is Visual Studio (presently 2017
or 2019 – either will work). When Unity was first installed
on your machine, it should have automatically installed a
version of Visual Studio on your machine. By default, Unity
installs Visual Studio 2017, although upgrading to 2019 is
free (using the free version of Visual Studio (Visual Studio
Community) that Unity uses). For the screenshots in this
chapter, we will be using Visual Studio 2017 since that’s
what’s installed by default. But if you’re running 2019, no
worries. Some of the colors might be a little different, but
the functionality is the same.
Before we get busy writing code, let’s make sure that the
installation is complete and that Unity knows where the
installation is.
470
Introduction to C#
FIGURE 13.4 Ensuring Visual Studio has the Unity libraries installed.
471
Creating Games with Unity, Substance Painter, & Maya
FIGURE 13.5 Ensuring that Unity knows to use Visual Studio for code creation and editing.
Why?
We’re going to be a doing a lot of testing. This means
a lot of playing the game. Currently, MainLevel is a big
472
Introduction to C#
473
Creating Games with Unity, Substance Painter, & Maya
print(“Hello World”);
The total code should look like Figure 13.8. Use File>Save
(Ctrl-S) in Visual Studio and return to Unity.
474
Introduction to C#
FIGURE 13.8 Code that allows for a simple message (Hello World) to be written to the Console.
Why?
When returning to Unity, the bottom right of the interface
might show a little spinning circle. This means that Unity
is compiling the code. What’s happening here is that Unity
is reading the code and trying to see if it understands
the instructions. If there are syntax errors, they will pop
up on the Console in red. Double clicking that error will
open the code again in Visual Studio to point out where
the problem might be. If there are no syntax errors and
Unity understands all the new instructions not much will
happen – and that’s a good thing.
What this script does is when the game starts (in the
Start() function, see?), the Console will print the string
(just a collection of characters) “Hello World!”.
475
Creating Games with Unity, Substance Painter, & Maya
FIGURE 13.9 After properly compiling, a script is added to the scene by dragging it
onto the object in the Hierarchy or the Inspector.
Why?
Most scripts do nothing if they just live in the Project
window. They need to be in the game to be active. Unity
hangs scripts off of GameObject to indicate that they
are actually to be executed when the game is played.
It’s a common mistake for beginning coders to write a
script and forget to apply it to their game.
Why?
Alright, so not terribly exciting so far. But this is an
important (and traditional) step to setting up code. The
Console writing this string out shows us that the script has
476
Introduction to C#
FIGURE 13.11 Moving the print line of code to be fired every frame.
FIGURE 13.12 Moving the print command to Update() means “Hello World!” is
printed every frame of the game.
477
Creating Games with Unity, Substance Painter, & Maya
Why?
It’s important to understand that functions not only
include instructions but have specific times to fire. In
Start(), the instructions are carried out when the game
starts. In Update(), they fire every frame. Sometimes we
need things to fire every frame (like listening for player
input), but usually Unity shouldn’t be tying up processor
cycles every frame.
Why?
The point of this tutorial is to make the doors slide open
as we walk up to them. In order to make this work, there
needs to be a way to actually move up to the doors – thus
478
Introduction to C#
FIGURE 13.14 Placed FPSController. Note that for this screenshot, the Intensity of
Directional LIght was reduced considerably to be easier to see.
479
Creating Games with Unity, Substance Painter, & Maya
Why?
This collider will become a trigger. It will trigger the doors
opening for us. So it needs to be about the size of the
doors, but have enough of it in front of the doors so they
open before we smack into them, and close behind us
once we’re through them.
480
Introduction to C#
FIGURE 13.16 Poorly placed Box Collider. In Unity, colliders are always color coded
in green.
FIGURE 13.17 The Edit Collider button will allow the size and shape of the collider
to be adjusted.
FIGURE 13.18 The adjusted collider. This will act as the trigger to open the doors
when we walk up to the door and close them behind us when we move away from it.
481
Creating Games with Unity, Substance Painter, & Maya
Step 6: Play the game and get stuck. Ctrl-P will allow
the player to try and walk up to the doors, but
because of the Box Collider we’ll be stopped
before we ever get to the doors.
Step 7: Convert the Box Collider to a Trigger. In
the Inspector, the Box Collider has a check box
for “Is Trigger”. Check this. Play the game and
you should be able to walk through the doors
again.
Why?
A Trigger is a sort of box collider that registers when
something has intersected with it, but it still allows
whatever hit it to pass through. The Trigger will trigger
some event that we’ll write into script.
Why?
This script is going to have a single purpose: open and
close the door. There is no work we need it to do every
frame or when the game starts. Therefore, there is no
need for Start() or Update(). Notice that the curly brackets
482
Introduction to C#
The code should look like Figure 13.22. Save and return
to Unity.
FIGURE 13.20 Because Visual Studio and Unity are tied, as a built-in function’s name begins to be typed, Visual Studio will
suggest some solutions.
483
Creating Games with Unity, Substance Painter, & Maya
FIGURE 13.21 When one of the hints is clicked, Visual Studio will automatically
format the function. Notice it has filled in arguments ((Collider other)) and placed the
starting and ending brackets.
FIGURE 13.22 Code that will let the developer know that the trigger is working.
Why?
This is a typical coding method. Create the trigger, check
to see if it actually gets activated. In the movies, its
common to see a coder laying down hundreds of lines of
code with a triumphant flourish. In reality, coders write a
line, see if it works, come back and write the next line, see
if it works, etc. Here it’s important to make sure that the
Trigger is working before adding any other code.
484
Introduction to C#
FIGURE 13.23 Applied SlidingDoorScript. Note that the script is applied to the same
object that has the Trigger (Box Collider).
FIGURE 13.24 Adding script to register when the player leaves the trigger. Upon
test playing the game, both print commands should be actuated (and show up in the
Console) as the player gets close and then moves away from the doors.
485
Creating Games with Unity, Substance Painter, & Maya
DOTween
So now comes the part where the doors actually move.
There are many ways to do this: we could animate the
doors in Maya and then play that animation in Unity when
the player enters the trigger, we could animate the doors
in Unity using Unity’s animation system and play those
animation clips when triggered, we could code it old
school by setting a target location and moving a certain
amount every frame until we reached the target amount.
All of these have their benefits, but we aren’t going to any
of them here. The animation paths are covered in other
chapters in this book, or can easily be found in plenty of
YouTube videos. The old school programming is just more
than we want to do at this point.
486
Introduction to C#
487
Creating Games with Unity, Substance Painter, & Maya
Why?
DOTween is just code that someone else has built that,
once imported into a project, allows the developer to
leverage the thousands of lines of DOTween code into
single commands. This is the power of expanding libraries
or bringing in other classes. The bounds of the game
engine can be nearly infinitely expanded in all directions.
But with great power comes great responsibility. In this
case, don’t move the Demigiant folder. The location of
classes like this matter. So treat Demigiant as sacred for
now and it will save you hassle later.
FIGURE 13.27 Adding DOTween to the list of libraries (and thus the list of commands that this script knows).
488
Introduction to C#
Variables
In C#, variables are buckets of information. A variable
can hold gameObjects, integers, numbers with decimals
(floats), strings of letters, and/or even things like booleans
(true or false). Variables are important for code as they
become the easiest way for a script to keep track of
any particular object, number, or text string. When the
developer populates a variable (puts something in the
bucket), the script is able to easily reach out and grab that
bucket and access whatever is inside of it without having
to do the hard work of going out and finding the object/
number/text/whatever each time it needs it.
489
Creating Games with Unity, Substance Painter, & Maya
FIGURE 13.28 Declaring two variables for lDoor and rDoor. These are public for now.
Why?
When Unity finishes compiling the code, the Sliding Door
Script component will look different in the Inspector.
Since we’ve added to public variables, the variables will
now be visible inviting the developer to populate them
(Figure 13.29).
490
Introduction to C#
FIGURE 13.30 Moving the doors to an open position and taking note of their
Position X values.
Why?
The line:
lDoor.transform.DOLocalMoveX(-.15f,
.5f);
491
Creating Games with Unity, Substance Painter, & Maya
FIGURE 13.31 Using DOTween to animate the doors opening and closing.
FIGURE 13.32 A quick shot of the documentation for DOTween that help us
understand what arguments the DOLocalMoveX expects to see.
492
Introduction to C#
FIGURE 13.33 Populating the lDoor and rDoor variables via script. In this case only
looking for objects that are children of whatever this script is attached to.
Why?
In this case, we want to make sure this code will work
for every instance of the door we have in the scene.
This method means that when the game very first starts,
before it does anything else (that’s what happens in
Awake()), it populates the variables itself by finding
objects among its children. When this is all done, all
the doors will open automatically as the player walks
up to them.
493
Creating Games with Unity, Substance Painter, & Maya
FIGURE 13.34 Making sure all the instances of this door will open as we approach
them.
494
Introduction to C#
FIGURE 13.35 Audio Source settings. This Audio Source component is attached to
the parent door.
495
Creating Games with Unity, Substance Painter, & Maya
Why?
An Audio Source indicates a location that an audio clip
will emanate from. The Audio Source component always
needs a clip (the actual sound file) to be defined. Turning
off Play on Awake makes sure that the sound only plays
when the player walks through it (which the script will
do in a minute). And finally, adjust the Spatial Blend to 3D
means that the player will hear the sound in their left and
right headphones when playing the game.
There’s lots more cool stuff (reverb zones, fall off, Doppler
effects) that can be done with Unity’s Audio system. We
won’t get to most of it here, but if you are interested, take
a deeper dive.
FIGURE 13.36 Adding a variable to hold the Audio Source just created.
FIGURE 13.37 Allowing the script to populate the doorSound variable with the
Audio Source component.
496
Introduction to C#
Why?
GetComponent<Type of Component>() is a powerful tool.
Any component can be accessed with any script in this
way. In the line of code shown in Figure 13.37, we are saying
“into the bucket (variable) doorSound, put the AudioSource
component that is also attached to this gameObject.”
Why?
Static objects can’t move. The doors are probably marked
as Static as they were set that way for light baking. But
now, we need them to move.
497
Creating Games with Unity, Substance Painter, & Maya
Step 36: Save and test. All the doors in the level should
open as the player approaches them, and close as
they move away. Further, the sound should play
as the player enters and leaves the trigger.
The first is the very first few lines of any page (Figure 13.39).
This shows the format that a tool actually has. So, in
Figure 13.39, we are looking at Instantiate (it means to
make an instance in the scene). There are many ways listed
there to use this. Instantiate (in bold) is the actual class
that we can use in script. In each of the lines shown there,
the various arguments it expects are listed.
498
Introduction to C#
FIGURE 13.39 The Unity API for Instantiate. Learning to read the API is key to success beyond any tutorial.
499
Creating Games with Unity, Substance Painter, & Maya
FIGURE 13.40 An example in the API for Instantiate. These examples are a great way to see something in action.
Conclusion
And with that we’ll leave this chapter. Through the course
of this chapter, we have created new scripts, attached
those scripts to gameObjects (which means they are
used in the game). Within those scripts, we’ve looked at
creating and populating variables. Using the variables we
have fired code-driven animation and played sounds.
500
CHAPTER 14
FPS Animations
501
Creating Games with Unity, Substance Painter, & Maya
502
FPS Animations
Why?
No need to set a project for now. The texture files will be
separate and assembled in Unity later. All that is needed
is the geometry and animation for now. However, it is
important to note that the file being animated here
already has the UVs complete and the materials applied
before the rigging and animation began.
503
Creating Games with Unity, Substance Painter, & Maya
FIGURE 14.2 The geometry that the FPSController will never see. Removing it from
the file will keep it streamlined and keep it from showing up in Unity.
FIGURE 14.3 Swapping to Animation mode. This produces new pull-down menus
to choose from.
504
FPS Animations
Why?
Changing Hierarchy to Below means that Maya will bake
the keyframe for all the objects below the selected object.
For us, this means all the joints for the rig will have their
keys baked in. Sliding the Current Time Marker in the time
slider would reveal that the first animation begins at frame
0 and ends at frame 560, thus the setting for Start/End
and setting the Start Time at 0 and End Time at 560.
The process of Baking the keys can take a while. It’s setting
an awful lot of keyframes as it goes. The progress can
be seen in the time slider at the bottom. Give it time to
complete.
Why?
Gun_grp and gunClip_CTRL_group both have keys on
them. Further, Gun_grp’s position is being defined by a
Parent Constraint. By baking the keys, the constraints are no
longer need to define the position of the gun and the clip.
505
Creating Games with Unity, Substance Painter, & Maya
FIGURE 14.5 Now that keys are baked, these constraints are no longer needed.
Why?
These constraints would likely make no real difference
in Unity. But cleaning up assets not needed helps keep
the files lean and the game engine running smoothly for
longer.
Why?
Strictly speaking, there are loads of other things we
could actually clean from the file. This rig is powerful
and complex, and actually has two joint chains and
only one deforms the mesh. However, once this asset is
inside Unity, all of that will be buried anyway, and while
unnecessary, the developer would never have to mess
with it. So it’ll stay.
506
FPS Animations
FIGURE 14.6 Deleting a few other things that helped in the animation process but
get in the way in the engine.
Why?
It is important that the old non-baked version of the
animations is not saved over. This baked version is great
for the game engine – but nearly impossible to edit. Keep
the old unbaked version in case animations need to be
adjusted.
507
Creating Games with Unity, Substance Painter, & Maya
508
FPS Animations
509
Creating Games with Unity, Substance Painter, & Maya
FIGURE 14.8 Exporting the grenade launcher textures from Substance Painter.
510
FPS Animations
FIGURE 14.10 In order to see adjustments to materials, bring the two files out into
the scene.
Why?
It is likely that some of these shaders will need to be
adjusted once the game is going. If desired, play with the
Materials a bit as they are being built. Don’t be afraid to
experiment (try turning the Metallic slider up for the guns
for instance) to get the look more like you’d like. In general
though, for now, the output from Substance Painter will
be a great baseline.
511
Creating Games with Unity, Substance Painter, & Maya
Why?
It was important to see these in the scene with the current
lighting scheme; however, as we start building in the
mechanics of the coding, this will most effectively happen
in a new scene.
Why?
Exactly where this should appear is up to preference. But
we prefer the gun to not take up too much space in the
512
FPS Animations
FIGURE 14.12 The Near Clipping Plane (highlighted) indicates the distance that the
Unity camera begins drawing geometry. Any geometry (like the arms) that are close
than this are “culled” or left out and not drawn.
game view. Thus we’ve got it not only slid down, but off to
the side.
513
Creating Games with Unity, Substance Painter, & Maya
FIGURE 14.13 Creating an Avatar for the imported rig. This avatar will allow us to
control the animations.
Why?
Just by way of explanation, in the Project window,
expand Ellen_Gun. There, among the children will be
something similar to Figure 14.14. This is the newly
created Avatar. There’s much more to be done with this
as we go.
Animations in Unity
There are several ways to work with Animations in Unity.
Each animation can be brought in as a separate asset
(which we will do later for the AI), or they can all come
in as one file – which is what is happening here. The fbx
Ellen_Gun actually has several animations that we need to
break up into Animation Clips. Currently, there is just one
(“Take 001”) that can be seen in Figure 14.14. But with a bit
of work in the Import settings, this can be broken down
into its constituent animation parts.
514
FPS Animations
FIGURE 14.15 Defining and Animation Clip. This one is the idle loop. The exact
frames came from the animator.
515
Creating Games with Unity, Substance Painter, & Maya
Controlling Animations
Unity’s Animator mechanism is a combination of visual
graph-making and coding. The core idea is that we will
create an Animator Controller (to control the animations,
you see), and then within this controller the developer
can establish states (which are really animations) and
transitions that define when to move between the states.
516
FPS Animations
FIGURE 14.19 Placing an animation clip into the Animator by dragging it from the Inspector.
517
Creating Games with Unity, Substance Painter, & Maya
Why?
A lot happens here all of the sudden. “idle_anim” is
represented as a state within the Animator, and since
it is the first state a transition (orange arrow) is created
between the Entry node and this new idle_anim state.
This means, “upon entry (when we first see the thing this
Animator is attached to), transition directly to idle_anim
(play that animation).” Since idle_anim was marked with
Loop Time (back in the Import settings of the Inpector),
and since there is no transition out of idle_anim, it will
keep looping idle_anim.
FIGURE 14.20 Bringing in the attack_anim from the Inspector, and then building a trigger named attack.
518
FPS Animations
Why?
Here we are setting up a pathway so that the animator,
from any place in the chart we’re building, can move into
attack_anim. We need to make sure the pathway only
happens when the “attack” trigger has been triggered
though.
Why?
Change the Transition Duration to 0 means don’t build in
any transition from whatever animation its playing and
the attack_anim. When the player presses the fire button,
the fire animation should play right away.
519
Creating Games with Unity, Substance Painter, & Maya
FIGURE 14.22 Defining the transition between Any State and attack_anim.
Why?
We’ll adjust this later, but for now, it means “when attack_
anim is done, move on over to idle_anim”.
520
FPS Animations
FIGURE 14.23 Having Unity listen (every frame) to see if the player presses the Fire1
button.
Why?
In C#, if statements take a particular form. In pseudocode:
if(this is true)
{
Do This Work;
}
521
Creating Games with Unity, Substance Painter, & Maya
FIGURE 14.24 Input Manager where the button named Fire1 is defined.
Why?
What this does is create two buckets and fills those
buckets with the GameObject Ellen_Gun and its
Animator component. From here on out, when we need
522
FPS Animations
FIGURE 14.25 Creating and populating variables so that PlayerControlScript knows who Ellen_Gun is and where its Animator
component is.
FIGURE 14.26 Triggering the attack trigger in the Animator attached to Ellen_Gun.
Step 40: Fire the attack trigger. Replace the print line
with that seen in Figure 14.26. Save and return
to Unity.
Why?
Triggers fire once and then reset (at least that’s what
they’re supposed to do). So, SetTrigger(“attack”) will fire
the attack trigger in the Animator, which will transition
from Any State into the attack_anim state. The Animator
is then set so that when the attack_anim is done, it
automatically goes back to idle_anim.
523
Creating Games with Unity, Substance Painter, & Maya
FIGURE 14.27 Creating an isWalking and isIdling boolean within the Animator.
Why?
Booleans will work a bit different than Triggers in
the Animator. While Triggers do just that – they
trigger something to happen – a boolean is keeping
track of a state of being. For instance, when the player
fires their weapon, the Animator can then check to
see if the character is idling or moving. If moving, play
the walk animations, if idling, play the idle animation.
In the Animator, these Booleans will be used when to
shift between states. Later, in script, these Booleans
will be turned on and off depending on the player’s
inputs.
Why?
Has Exit Time means the animation must complete before
transitioning. When moving from idle to walk, we don’t
want to wait until the idle completes – when the user
starts moving, we should immediately start playing the
524
FPS Animations
525
Creating Games with Unity, Substance Painter, & Maya
FIGURE 14.30 Settings for the transition between attack_anim and walk_anim.
Why?
In this case, it will be important for the attack animation
to complete; thus, Has Exit Time remains checked. It is
important to remember to set up the isWalking Boolean
set to true as the condition that must be met to move
from attack_anim to walk_anim.
526
FPS Animations
FIGURE 14.31 Defining the situation in which to move from attack_anim to idle_anim.
Why?
The “||” means “or”. Alternatively “&&” means “and”. This
code means: “if the player presses (and holds) the buttons
Vertical or Horizontal, then go to the ellenGunAnimator
527
Creating Games with Unity, Substance Painter, & Maya
FIGURE 14.32 Transition between walk_anim and idle_anim. No Exit Time and isIdling being true as the Condition that must
be met.
FIGURE 14.33 Turning Booleans on and off by listening for the buttons “Vertical” and “Horizontal”.
528
FPS Animations
and set the isWalking Boolean to true, and set the isIdling
to false. Otherwise (else), if the player is not pressing
Vertical or Horizontal, then set isWalking to false and
isIdling to true.”
529
Creating Games with Unity, Substance Painter, & Maya
FIGURE 14.37 Turning off the Ellen_GrenadeLauncher when the game starts.
530
FPS Animations
Tutorial Conclusion
And with that we’ve used code to control different
animation clips by listening for user input. There’s loads
more that can be done with these techniques, and in fact,
there are multiple animation still unused. But once the
core idea of the Animator and firing triggers or flipping
Booleans in the Animator with script is understood, any
animation can be played when the developer wants it.
531
CHAPTER 15
Raycasting and
Render Textures
533
Creating Games with Unity, Substance Painter, & Maya
Why?
You may have already organized the geometry when
modeling it way back in Chapter 1. But the focus back
then was on form and topology, not on organizing
534
Raycasting and Render Textures
535
Creating Games with Unity, Substance Painter, & Maya
FIGURE 15.2 Animation window with limited functionality. However, after creating an Animator and Animation Clip, much
will become possible.
Why?
Organization is important. Always. Taking a moment to
save animations in an Animations folder makes sure there
are no assets just floating around the Assets folder.
536
Raycasting and Render Textures
FIGURE 15.4 Results show the Property in the Animation window and a keyframe
(little gray diamond) at frames 0:00 and 1:00.
Why?
When Unity creates a property, it creates two keyframe
(gray diamonds) as well. Arbitrarily, Unity creates them
at 0 seconds and 1 second. Notice that the time unit in
Unity is 60fps. So 0:40 is 0 seconds and 40 frames into
the animation. 60 frames is 1 second. To make this work,
we’ll edit the keyframes Unity creates by default and add
some more.
537
Creating Games with Unity, Substance Painter, & Maya
FIGURE 15.6 Using the Go To Next Keyframe button is a quick way to get to the
next spot in the timeline that we need to overwrite.
Why?
In the Animation window, hit the Play button at the top
left. Unity will play a much-too-fast animation of the
camera swinging from −90 to 90 in Y. We’re not worried
about timing quite yet, just getting the values in.
538
Raycasting and Render Textures
FIGURE 15.7 Add a Keyframe Button. Adding a keyframe this way later than an
extant keyframe will pause the animation.
Why?
The last two steps are making sure that (1) the animation
loops because the first and last keyframe are the same
(Rotation Y: −90) and making sure that there is a second’s
pause as the camera reaches its widest part.
539
Creating Games with Unity, Substance Painter, & Maya
Why?
This will be the animation clip that rotates only 90 degrees
(for when a camera is placed in a corner). Although we
could come back and make this animation clip anytime
we needed to, doing it now while we’re already in the tool
will save time.
540
Raycasting and Render Textures
Why?
Setting up this empty state and then making it the
default eans that there is no default animation that plays.
The camera is still by default. This will allow us to place a
camera without animation if it helps the game play.
541
Creating Games with Unity, Substance Painter, & Maya
FIGURE 15.13 Setting up transitions from the default (still) New State to the two animation states.
542
Raycasting and Render Textures
Why?
Much of this script should look pretty familiar. It creates
a variable (called myAnimator) that stores the Animator
component. In the Awake(), we populate that variable.
And then in the Start(), we set the Booleans created in
earlier steps.
543
Creating Games with Unity, Substance Painter, & Maya
Tutorial Conclusion
And with that we have a customizable animated camera.
It still can’t “see” the player, doesn’t have a spotlight, and
doesn’t render to a monitor, but we’ll solve that soon.
544
Raycasting and Render Textures
FIGURE 15.17 RaycastSource is a child of the security_cam_outer_shell_geo. Note that in 3D space, RaycastSource is moved
just in front of the lens.
545
Creating Games with Unity, Substance Painter, & Maya
Why?
By making this empty GameObject a child of the shell,
when the camera rotates, this will rotate with it. By
putting it in front of the lens, we ensure that the ray that
will be cast from this object doesn’t get stopped by the
camera itself.
Why?
This script could be attached to a lot of things and,
in fact, would make the code a little easier if it were
attached to RaycastSource. However, the idea here to
not hide scripts in places that are tough to remember
where they are attached. Since security_cam already has
the CameraAnimationChooseScript, putting this script
on the same object keeps the camera-centric scripts
consolidated.
Why?
Up to now, we’ve generally been working with private
variables and populating them via script. In this case,
we’ll make the variable public and define its content
in the Unity editor. rcSrc will store the RaycastSource
GameObject just created.
546
Raycasting and Render Textures
FIGURE 15.19 The basic mechanics of a Raycast (plus a little pizzazz with the DrawLine so we can see the ray).
Why?
In this case, every frame needs to be reporting what the
camera sees. Therefore, we put it in an Update() function.
RaycastHit thingHit;
Physics.Raycast(rcSrc.transform.
position, rcSrc.
TransformDirection(Vector3.forward),
out thingHit);
547
Creating Games with Unity, Substance Painter, & Maya
Finally, the last line draws a yellow line (only visible in the
Scene view) that starts where the RaycastSource is and
ends when the ray hits something.
FIGURE 15.20 The LineDraw allows the developer to see the path the Raycast takes.
Notice that this line is not visible in the Game window – only the Scene. It is meant
only for the developer.
FIGURE 15.21 Adding code that reports back on what the ray casts against.
548
Raycasting and Render Textures
FIGURE 15.22 The console showing (every frame) what object the RaycastSource is
raycasting against.
Why?
Anything can be assigned a tag. Tags can be used to
classify a group of types of objects. So, we could label
all the bad guys as “Enemies” so that we don’t have to
compare names in code but rather tags (or groups of
types of objects). “Player” is a built-in tag, but custom tags
can be created using Tag>Add Tag…
549
Creating Games with Unity, Substance Painter, & Maya
FIGURE 15.23 The animated camera in action with the Console reporting back on the various objects the ray casts against.
550
Raycasting and Render Textures
FIGURE 15.25 Altered script to only holler if the camera has “seen” the player.
FIGURE 15.26 A smart camera that knows when its hit the player. The line renders
red and the Console calls out when the thingHit contains an object tagged as “Player”.
Tutorial Conclusion
“Now wait a minute!” I hear you saying, “This is hardly a
functioning game mechanic.” You’re right. Currently a
script that writes to the Console means little to the player.
551
Creating Games with Unity, Substance Painter, & Maya
552
Raycasting and Render Textures
Why?
Adding a lot of cameras to the scene can be expensive.
After all, suddenly with extra cameras Unity is drawing
things more than once. To help minimize the expense,
553
Creating Games with Unity, Substance Painter, & Maya
FIGURE 15.28 Adding a Spotlight to give the player a hint about where the camera
can see.
Why?
Render Textures are textures that show what some
camera is rendering. The process here will be to make the
camera render to this new DefaultRenderTexture, and
then apply this DefaultRenderTexture to some material in
the scene.
554
Raycasting and Render Textures
FIGURE 15.29 Extracted monitor screens made into their own prefabs.
Why?
So we’re cheating a little bit here. There are ways to use
the current versions of the monitors and have different
parts of the shader show different materials (using HDRP
Layered Lit shaders). And that is a more efficient way
of handling this. However, extracting the geometry
of the screens in Maya (which is what the fbx in Step 6
represents) is an easier solution with what we’ve covered.
We’ve included the Maya files with the screens extracted
in the support files if you want to take a closer look.
The basic process in Maya was as follows: 1) select the
polygons of the screens, (2) edit Mesh>Extract to split
the polygons off, 3) remap each screen to its own UV
space so it completely filled the UV quadrants, 4) assign
555
Creating Games with Unity, Substance Painter, & Maya
556
Raycasting and Render Textures
FIGURE 15.31 Making the Camera that is a child of the security_cam geometry so
that it renders to the DefaultRenderTexture.
FIGURE 15.32 Using a Render Texture to define the Color attribute of the Unlit
material. The screen shows what the camera sees.
Why?
The Unlit shader means that this surface won’t be affected
by the lights in the scene (as a screen should).
557
Creating Games with Unity, Substance Painter, & Maya
FIGURE 15.33 Code to turn a camera off if it is not being rendered to a monitor in the scene.
Why?
This is an important step. If the game has ten cameras (an
arbitrary number at this point), but only three monitors,
we want to make sure that only three cameras are doing
the work of rendering to a textures. Further, if a camera
isn’t rendering to a texture, it shouldn’t be on at all. What
this script does is create a public Boolean (think of this as
a switch) that we can choose to turn on or off in the editor.
When the game starts, each security_cam (that has this
script) will check to see if the renderToTexture Boolean is
true; if it is not (!= means “is not equal to”), it clears out the
Target Texture attribute of the Camera and shuts it off.
558
Raycasting and Render Textures
FIGURE 15.34 Final completed security_cam. This prefab is ready to be placed and configured in the scene.
FIGURE 15.35 Some placed cameras in the scene. Place as you’d like, but make sure there is at least one in the armory and
none in the first room the game starts at.
Step 16: Play test. Play the game and make sure
that the new camera have not smashed the
frame rate on the game. Depending on the
power of your machine and video card, you
could be bumping up against how much can
be drawn.
559
Creating Games with Unity, Substance Painter, & Maya
Conclusion
Raycasting is the key concept of this chapter. Render
Textures are fun, but if Unity is being persnickety about
them, no worries. As you place the cameras throughout
the level, you’ll likely find the Console firing that you’ve
been caught as you wander through the level to test.
This means much of the baseline mechanics are working!
In the next chapter, we will start working with weapons.
We’ll make the grenade launcher work and the pistol
fire. We’ll use techniques already covered (Raycasting
will make another appearance) and cover new ideas
(Instantiate will make its debut).
560
CHAPTER 16
Weapons
561
Creating Games with Unity, Substance Painter, & Maya
562
Weapons
FIGURE 16.2 Continuing with particle effects to create pressurized steam effects.
563
Creating Games with Unity, Substance Painter, & Maya
FIGURE 16.3 And finally using particle effects for rising steam.
FIGURE 16.4 A simple scene. Make sure the FPSController is in the scene and that
any other Main Camera has been deleted.
564
Weapons
FIGURE 16.5 Code that listens for the player pressing the Fire1 button. Currently,
this just plays an animation through the Animator Controller by turning on the
Boolean “attack”.
Why?
A string is a collection of characters. These can be
numbers or letters. It’s easiest to think of a string as a
word. The word means nothing to Unity, but can be very
easy for a user to understand. In this case, we will store
which weapon is active by putting in this string variable
the words “Gun” or “Grenade”.
Why?
Notice that these two lines are just added to code already
in the script. This just makes sure that the script provides
an easy way to check if the weapon is active later. Notice
that strings are always in quotes.
565
Creating Games with Unity, Substance Painter, & Maya
FIGURE 16.7 Make sure the script knows which is the activeWeapon.
FIGURE 16.8 An added line at the Start() when the grenade launcher is put away.
FIGURE 16.9 Reworking the Fire1 area of the code so that different work is done
depending on which weapon is active. At this point, the comments just leave us a
note of what needs to be done.
566
Weapons
FIGURE 16.11 After duplicating, separating the Grenade from the structure of the FPSController.
Why?
Eventually, we’ll engage in a bit of sleight-of-hand. The
grenade (grenade_launcher_grenade) is used in things
like the reload animation, and so it needs to stay a child
of the FPSController. However, when the player presses
the Fire1 button, they need to see a grenade go flying out.
This new Grenade is going to be the actual thing that is
launched, and we’ll quickly turn off the one that’s still on
the end of the gun.
567
Creating Games with Unity, Substance Painter, & Maya
Why?
Eventually it will be important for this Grenade to know
when it has actually hit something – when it will explode.
We have already used the built in class OnTriggerEnter
(remember the doors?). In the coming steps, we’ll use
a sister class called OnCollisionEnter that fires when
568
Weapons
Why?
The GrenadeLaunchPoint is going to be the location
where we create the new Grenade each time the player
fires. By making the launch point be at the same place as
the grenade in the gun, we can be sure that the Grenade
matches the position of grenade_launcher_grenade.
569
Creating Games with Unity, Substance Painter, & Maya
Why?
We are going to instantiate many of these Grenades, and
when the Grenade hits something it will destroy itself. By
making Grenade a prefab, we can instantiate it again and
again as needed.
FIGURE 16.17 Instantiating the Grenade at the GrenadeLaunchPoint when the player hits Fire1.
570
Weapons
Why?
The details for Instantiate can be found in the API
(Help>Scripting Reference). Among the things the API
will provide is that instantiate basically uses the format
Instantiate (thing to instantiate, where to instantiate
it, rotation to instantiate it at). So we are instantiating
whatever is in the grenade variable, the position
of grenadeLaunchPoint, and using the rotation of
grenadeLaunchPoint.
FIGURE 16.18 Creating Grenades is alright, but not quite what we had in mind.
FIGURE 16.19 Adjusting the Instantiate section of the code to give velocity to the grenades after they are instantiated.
571
Creating Games with Unity, Substance Painter, & Maya
Why?
What really is happening here is that we are creating
a temporary variable (clonedGrenade) into which we
instantiate the grenade. Because we instantiate it into this
bucket, we can then talk to it and tell it to have velocity
(since it’s a Rigidbody). Velocity (as per the API) needs
a vector, which means we need to give it a direction
(grenadeLaunchPoint.TransformDirection(Vector3.
forward)), which is the +Z direction of the launch point),
and a magnitude (in this case 10).
FIGURE 16.20 Firing some grenades that fly away and stop when they hit a surface.
FIGURE 16.21 Creating a float variable that will allow changing the speed to
happen in the Unity editor.
572
Weapons
FIGURE 16.23 Creating code for the Grenade so that it instantiates an explosion and then destroys itself when it hits
something.
573
Creating Games with Unity, Substance Painter, & Maya
Why?
With what we’ve covered, this should be pretty clear.
The new OnCollisionEnter simply defines when the code
should fire (when the thing this script is attached to enters
a collider). The new thing is the Destroy() command.
Destroy can be used to destroy all sorts of things including
components, scripts, and, in this case, the GameObject
that this script is attached to.
Step 22: Apply and tie up the new script. Edit the
Grenade prefab by double clicking it to open the
Prefab Editor. There, drag the new GrenadeScript
onto the Grenade. Then drag TinyExplosion
from the HDRP_ParticleEffects folder into the
Explosion input field. Click back on Scene at the
top left of the Prefab Editor.
Step 23: Test and witness the never-ending
explosion.
Step 24: Edit TinyExplosion to not loop and
self-destroy. In the Project window, select
TinyExplosion. In the Inspector, turn off Looping
and set Stop Action: Destroy (Figure 16.24).
Step 25: Test and save.
Step 26: Add an AudioSource to the TinyExplosion.
Find a short sound of an explosion (likely 2
FIGURE 16.24 Setting the TinyExplosion so that it only plays once and then destroys
itself when complete.
574
Weapons
FIGURE 16.25 Playing another sound when the layer presses Fire1.
575
Creating Games with Unity, Substance Painter, & Maya
FIGURE 16.27 Turning off the dummyGrenade on the frame that we instantiate the Grenade with velocity.
Why?
This new line is another illustration of how to get a
particular component of a GameObject, and then how
to disable the renderer. In this case, we wouldn’t want to
use dummyGrenade.SetActive(false) as it would turn itself
off completely and the GrenadeLaunchPoint beneath it,
but we need that GrenadeLaunchPoint to define where
to instantiate the new Grenade. So, instead, we’ll just
turn the renderer off for the dummy grenade and make
it invisible.
576
Weapons
FIGURE 16.28 Setting up a boolean that will let us turn the ability to fire the Grenade off and on.
Why?
No need for this variable to be public. We’ll be controlling
it all within script. Sometimes you want a Boolean public
to debug; but until then, there’s no need for this to be
cluttering up the Unity Editor.
Why?
We’ve alluded to && before; but as a review it means “and”.
So if the active weapon is “Grenade” AND canFireGrenade
is true, then do the work in the brackets.
FIGURE 16.29 Checking to see if we can fire the grenade and then turning off the ability to do so.
577
Creating Games with Unity, Substance Painter, & Maya
FIGURE 16.30 Creating a new IEnumerator, ReloadGrenade(), that turns dummyGrenade back on and flips the
canFireGrenade switch back on.
Step 35: Test and witness that the player can only fire
one grenade.
Step 36: Create a new Ienumerator called
ReloadGrenade() that shows the dummyGrenade
again and sets canFIreGrenade back to true with
some wait times in between. Figure 16.30 the
complete IEnumerator.
Why?
Two important things here: what is an IEnumerator and
why do we need it. The IEnumerator cannot be inside
another function; so, for instance, it needs to be outside
of the Update() function where we have been doing all
the work lately. The screenshot shows the end of the
Update() function (the last closing bracket) and that’s
where the new ReloadGrenade() IEnumerator should
be built. But notice, that it still needs to be inside the
PlayerControlScript class, so it is still before the last
bracket for the class.
IEnumerators work much like a regular function, except
that they must contain a “yield” statement. Yield in this
case means “wait.” What this IEnumerator does is wait for
1.25 seconds before turning the dummyGrenade back on,
and then waits another 0.5 seconds before allowing the
user to fire again. These wait durations might seem a little
arbitrary right now, and they were, but with a little testing
these were the timings that became apparent once all the
animations were tied in together (in a few steps).
578
Weapons
FIGURE 16.31 Creating the command start the work of the IEnumerator as a coroutine.
Why?
This work inside the IEnumerator is meant to be firing as
the script goes on doing its other work. It’s why we are
starting it as a “coroutine”. In this situation, its actually the
only way to fire an IEnumerator.
Why?
It will be important that the attack_anim plays all the way
through before moving onto the reload_anim. Therefore,
Has Exit Time is checked and Exit Time is set to 1.
579
Creating Games with Unity, Substance Painter, & Maya
580
Weapons
Tutorial Conclusion
That’s all for the Grenade Launcher for now. Later, it will
be important that the sentient Grenade is a little smarter.
We’ll need it to know when it hits a camera to destroy
581
Creating Games with Unity, Substance Painter, & Maya
But, this is a good start. At this point, the player has one
active weapon that convincingly fires a projectile and
that projectile explodes when it hits something. The next
tutorial will be much faster as it will redo much of what
we’ve talked about here for the small pistol.
582
Weapons
FIGURE 16.36 Creating the GunLaunchPoint, maneuvering it to the correct location manually, and placing it in the appropriate
place in the Hierarchy.
583
Creating Games with Unity, Substance Painter, & Maya
Why?
Don’t worry too much what this will look like. It will be so
small and move so fast the player won’t even be able to
see it. We will be adding the Trail Renderer to make it a bit
more visible in the game. However, getting the Colliders
and Rigidbody set up correctly will be important to make
this bullet actually do work once it’s in the scene.
Why?
Trail Renders are lines that are drawn behind an object as
it moves through space. You’ve likely seen this effect in
hack-n-slash games with a fast moving sword. Here, we’ll
make a small line trail behind the bullet at its fired.
Why?
Notice that in the Width section the first Key is very, very
small (0.015). The second Key was added by right clicking
on the red line and choosing Add Key. This second key is
moved down to 0 on the Y. These values were found by
moving the GunBullet, turning the values down, moving
GunBullet again, turning the values down again, and so on.
584
Weapons
FIGURE 16.38 Adjusting the width and length of the trail renderer, and making sure
it doesn’t cast shadows.
Why?
That bright pink in Unity actually always indicates that
a material or texture is missing. At this point, the Trail
Renderer doesn’t have a material yet, so it defaults to that
585
Creating Games with Unity, Substance Painter, & Maya
pink to let the user know that one needs to be built and
assigned.
FIGURE 16.40 Creating and setting up the Trail Renderer Material for the bullet.
586
Weapons
FIGURE 16.42 Filling in the variables to get started on the gun mechanism.
Why?
It’s fun to just write a lot of code, but it’s often helpful
to take a second to fill them up in Unity before writing
a bunch of new code. It’s very common for beginning
coders to write a bunch of code and then not be able to
run the game as Unity throws an error that the variables
are populated.
587
Creating Games with Unity, Substance Painter, & Maya
FIGURE 16.44 Constructing the bullet weapon to work very similar to the grenade.
FIGURE 16.45 A simple BulletScript to destroy the bullet when it hits a collider.
FIGURE 16.46 Temporarily turning off the ability to fire the gun when its fired; but starting the Coroutine that will turn it back
on again.
588
Weapons
FIGURE 16.47 Waiting for the 12 frames (0.2 seconds) before allowing canFireBullet
to be true again.
FIGURE 16.48 Deducting 1 from ammoCount each time Fire1 is pressed when activeWeapon is Gun.
Why?
ammouCount--; is actually short for
ammoCount = ammoCount − 1; In other words,
“ammoCount is now equal to whatever ammoCount was
minus 1”.
Why?
So this IEnumerator triggers some Booleans in the
ellenGunAnimator that haven’t been created yet. But we
should still be able to see what the code is doing: it sets
589
Creating Games with Unity, Substance Painter, & Maya
FIGURE 16.49 Checking to see if there are still bullets. If not, canFireBullet becomes false and BulletReload (an IEnumerator we
haven’t built yet) will start. Notice that the PauseGun() mechanism is moved down into the else statement.
590
Weapons
FIGURE 16.52 A new Boolean parameter called needReload that is expected back
in code.
Why?
So when the player hits the Fire1 button, the code
checks to see if ammo is more than 0. If not, it sets the
needReload parameter to true in the Animator. So,
the Animator, when it finishes attack_anim, sees that
needReload is true and moves onto reload_Anim. Or at
least that’s what it should do. We need to make sure it
doesn’t first attempt to head to idle_anim or walk_anim
because isWalking or isIdling will also be true.
591
Creating Games with Unity, Substance Painter, & Maya
FIGURE 16.53 The settings for the Transition between attack_anim and reload_anim.
FIGURE 16.54 Ensuring that attack_anim only moves to idle_anim or walk_anim if needReload is false.
592
Weapons
Tutorial Conclusion
We’ll leave the gun here. There is still work to be done.
Some you know how to do (and should), like adding a
sound when the pistol is fired. Other things like making
sure the bullet actually does damage to something will be
covered in later chapters.
For now, relish the testing that both weapons work. Tweak
the settings that are needed to give the game the feel you
find pleasing and then move onto the last tutorial to make
sure the weapons are accurate.
593
Creating Games with Unity, Substance Painter, & Maya
FIGURE 16.56 Changing the Canvas so that if the player’s screen gets bigger or
smaller, the UI will stay the same size on screen.
Why?
We will talk much more about his later as understanding
UI is important to a cohesive game play experience. For
now, suffice it to say, by holding the Shift and Alt buttons
594
Weapons
FIGURE 16.58 ReticleUI placed in the middle of the screen. Well, it’s not a reticle
quite yet…
595
Creating Games with Unity, Substance Painter, & Maya
Why?
This Reticle.psd file has an alpha channel build in to
allow parts of the image to be transparent. By setting the
import settings to recognize the file as a Sprite, Unity will
automatically find the alpha channel and prepare the file
for low-overhead, high-fidelity, UI display.
596
Weapons
FIGURE 16.61 The current problem with our weapons system: the weapons don’t
shoot at the reticle’s location.
597
Creating Games with Unity, Substance Painter, & Maya
FIGURE 16.63 Rotating the weapon would work at one distance only…
598
Weapons
FIGURE 16.64 As soon as the wall was closer (or further), the impact and reticle
would no longer line up.
FIGURE 16.65 Creating a variable to store the Transform of the FirstPersonCharacter (actually the camera for the FPSController)
and then filling it with code on Awake().
599
Creating Games with Unity, Substance Painter, & Maya
FIGURE 16.66 Raycasting and then pointing the launch points at the place the ray is casting against.
Why?
The only real new idea here is the LookAt() command.
Look at takes the positive Z axis of an object and points
it towards a location. In this case, it’s the thingHit.point.
Remember that thingHit is the Raycast hit created a
couple of lines earlier.
This work is done inside the Fire1 area. Why not earlier in
the Update() function? The way this is working is that on
the single frame that the player presses Fire1, a single ray
is shot out, where it strikes is stored, and the launch points
point at it. Then, later in the same frames a projectile is
sent in that direction. If this were outside the if (Input.
GetButtonDown(“Fire1”)) section, it would be doing all
that work every frame. That’s a lot of work to do 60 times a
second when it could be done once the player pushes the
button.
600
Weapons
FIGURE 16.67 Raycasting and projectile weapons working together for good.
Conclusion
For now we’ll leave weapons behind…but not for long!
Still to come are UI elements that help the player know
how much ammo they actually have. Still to come is
the ability for the grenades and bullets to actually do
something in the game (destroy a camera, or shoot a bad
guy, etc.). There’s much to still do, so keep reading to find
out more!
601
CHAPTER 17
AI
603
Creating Games with Unity, Substance Painter, & Maya
FIGURE 17.1 A sample AITest scene. No specific rules here, just a simple scene to
develop code in.
604
AI
Why?
“Wait, I thought we weren’t doing lighting here,” you may
be seeing. And you’re right. The Static checkbox actually is
a drop-down menu that if clicked will show there are a lot
of flavors of “Static.” We used this to mark things that were
to be baked in the lighting scheme. However, by using the
605
Creating Games with Unity, Substance Painter, & Maya
Why?
So what are we seeing here? The cyan-colored NavMesh
will leave holes for walls and pillars. This NavMesh is
where a NavMeshAgent can move. If the NavMeshAgent
needs to move closer to the walls, this can be adjusted in
606
AI
Notice that in the Bake tab there are settings for Max
Slope and Step Height. The Max Slope determines how
steep an incline needs to be for the NavMesh to decide
if the NavMeshAgent can walk up it, and when it ceases
to be a slope and becomes a cliff. Similarly, Step Height
determines how tall a step can be before it’s no longer a
step and a ledge that the NavMeshAgent can’t walk up. In
most cases, the default settings work just fine for Agent
Radius, Max Slope, and Step Height; but if the model
has very steep stairs, or really narrow doorways, these
sometimes need to be adjusted.
FIGURE 17.3 Our cinnamon Tic-Tac. Notice that it has a Capsule Collider, but the
green cylinder around it is the visual representation of the NavMeshAgent component
(that can be seen in the Inspector too).
607
Creating Games with Unity, Substance Painter, & Maya
FIGURE 17.4 Laying the groundwork to chase the player by making sure the script
knows who the player is.
Why?
There are lots of ways to make sure the script knows
who the player is. The variable could have been public,
and then we could have dropped FPSController into
the variable. But that would have meant that this script
would have only worked in this scene with this instance
of FPSController. But we want to build so that the script
is reusable; so having the script self-populate the player
is a better long-term strategy. We could have also used
GameObject.Find(“FPSController”) instead, which finds
an object by name. But this can be a little brittle as well
if we end up with a different controller sometime. Since
we have a Player tag set up for the doors already, we’ll
leverage that mechanism here.
608
AI
FIGURE 17.5 Adding UnityEngine. AI will allow this script to understand when we
start talking about NavMesh and NavMeshAgents.
FIGURE 17.6 Defining the NavMeshAgent, and telling it to set its destination to
wherever the player is.
Why?
So notice that there are three steps here. First, creating a
variable (called myAgent) to hold a NavMeshAgent. Then
in the Awake() function, this myAgent variable is filled by
getting the NavMeshAgent component that is attached
to whatever GameObject this script is attached to. And
finally, every frame (by using the Update() funtion), we use
the SetDestination class (that is part of NavMeshAgent
component) to define where the AI is supposed to go; in
this case, wherever the position of the player is.
609
Creating Games with Unity, Substance Painter, & Maya
FIGURE 17.7 Making a variable to store the distance to the player. Then, every frame, measuring the distance and chasing the
player if that distance is less than 10.
Why?
The API reports that distance can be measured
using Vector3.Distance(object a’s position, object b’s
position). So, the code here first creates a variable called
distanceToPlayer to store a number. Then, every frame,
that variable is filled by the measurement between object
a (the GameObject this script is attached to (transform.
position)) and object b (player’s position).
Once the script has that number, it can see if it is less than
10. If it is, then it sets the NavMeshAgent’s destination to
that of the player’s. If not, it gives up (ResetPath()).
610
AI
FIGURE 17.8 Speeding up development time by making the chase distance an editable variable.
Why?
OnDrawGizmosSelected() means “draw some gizmos
when this GameObject is selected.” Within that function
we’re defining the color, and then using Gizmos.
DrawWireSphere(center of sphere, radius of sphere),
we draw a wire sphere. The sphere is centered on
the GameObject this script is attached to (transform.
position) and the radius is the chaseDistance. Back in
Unity, when the capsule is selected it should look like
Figure 17.10.
611
Creating Games with Unity, Substance Painter, & Maya
FIGURE 17.10 Results of OnDrawGizmosSelected. Notice this only draws when the
capsule is selected.
FIGURE 17.11 Making the player stop when they are close enough so attack. Later here, the AI will actually attack and fire their
pistol.
612
AI
FIGURE 17.13 Changing the color and drawing another wire sphere to show the
attackDistance.
613
Creating Games with Unity, Substance Painter, & Maya
FIGURE 17.14 Wire spheres showing both the chase and attack distances.
Tutorial Conclusion
Roughing out basic mechanics with a simple capsule
is a great way to begin to understand how the game
would play. There are lots of other things that could be
done here. Could you make the capsule patrol between
developer-defined waypoints? Could you make the
waypoints random? Could you change the speed from a
walk during waypoint patrol to run when chasing? These
are all possibilities, and things you may consider as you
look at advancing what you know.
614
AI
Why?
These particular measurements will most assuredly
be wrong in the long run. These measurements aren’t
really the size of the character, but rather the size of the
calculation that allows the AI to avoid things (Obstacle
Avoidance). Later, as the game takes shape, it’s likely that
this will need to get a little bigger or smaller as we see
how EllenEnemy actually works around obstacles, but
615
Creating Games with Unity, Substance Painter, & Maya
616
AI
Why?
What’s actually happening here is that the NavMesh is
not right on top of the meshes it is representing. In other
words, in this case, the NavMesh is not on the floor. This
can be seen if the Navigation tab is activated (over by
the Inspector, remember). To compensate for this, we
will move the character a bit lower in relationship to the
NavMeshAgent.
617
Creating Games with Unity, Substance Painter, & Maya
FIGURE 17.18 Adjusting the Base Offset to get the character closer to the floor.
618
AI
FIGURE 17.19 Creating a boolean to keep track of whether the character is chasing
or idling, and triggers to set off attack, got hit, and dying animations.
Why?
Yes, yes, it’s not right now. She does indeed chase the
player, but she chases stuck in the idle pose we set
up in Chapter 12. Luckily, we have a plethora of other
animations to choose from, including runs and attacks. We
just need to get them plugged into the Animator, and fire
those animations via the script.
Why?
In this case, the character is going to be idling, chasing,
attacking, getting hit, or dying. The triggers for attack,
gotHit, and die should be able to be fired at any time –
therefore, they will be triggers. But when the AI is not being
triggered by one of those events, it will either be chasing
(isChasing) or it won’t (isIdling). So we only need one
Boolean to keep track of these two animation states.
619
Creating Games with Unity, Substance Painter, & Maya
Why?
The looping should be pretty obvious; we want this
animation to continue to loop until we move onto
something else. The Root Transform Rotation is a little
trickier. Without it checked, if the animation is played
(down at the bottom of the Inspector window is a little
preview window with a play button), the animation runs
(or shoots) slightly to the side. By baking the rotation
based upon the Original, the animation will be reoriented
so that it runs/shoots right along the positive Z axis.
This will be important because the character’s orientation
is being defined by the NavMeshAgent, so the animation
should always be facing straight forward.
620
AI
FIGURE 17.21 Import Settings for non-looped animations for getting hit and dying.
Placing Animations
in the Animator
Now that the animation clips have been prepared, they
can be imported into the Animator as states. As we did in
earlier chapters, just grab the FBX files from the Project
window and drag them into the Animator.
621
Creating Games with Unity, Substance Painter, & Maya
FIGURE 17.23 Transitions from Any State to out three triggered states.
622
AI
FIGURE 17.24 Transition setting for Any State->Shooting using the trigger attack.
623
Creating Games with Unity, Substance Painter, & Maya
Why?
In moving between idle and running, this uses a single
Boolean: isChasing. If it’s true, we’re running, if it’s not,
we’re idling.
FIGURE 17.28 Providing a way out of getting hit and shooting back into idling.
624
AI
FIGURE 17.30 Creating transitions out of shooting and getting hit back to running.
625
Creating Games with Unity, Substance Painter, & Maya
FIGURE 17.31 Setting the conditions for moving from getting hit and shooting back
into running.
FIGURE 17.32 Creating a variable to store the Animator component in the script.
Why?
Just as a quick review, from now on in this script when
we need to manipulate the Animator component that is
attached to EllenEnemy we just use myAnimator.
626
AI
FIGURE 17.33 Making the animations be the determining factor in how quickly the
character moves (not the Move Speed in the NavMeshAgent).
Why?
Remember in earlier tests, EllenEnemy would glide
along the ground in idle pose? This was because the
NavMeshAgent was defining the speed at which she
moved. However, now we have plugged in animations
that have their own displacement. In order to get
the feet to stay still when they plant for each step,
the animations need to determine the speed. This
line, myAgent.updatePosition = false; means that the
NavMeshAgent isn’t in charge of moving the character
any longer.
FIGURE 17.34 Keeping the NavMeshAgent and animated character close together.
627
Creating Games with Unity, Substance Painter, & Maya
Why?
The new lines shown in Figure 17.34 come from Unity’s API
(“Coupling Animation and Navigation”). It’s mostly beyond
what we want to cover in this volume, but what it does is
make sure that if the NavMeshAgent (which is striving to
get to the Player when chasing) gets further away from
the character than the character radius, to then snap back
towards the character. Remember this weird little chunk
of code when we see this all in action. The NavMeshAgent
(when selected) will look weird, but the functionality will
be solid.
628
AI
FIGURE 17.36 Flipping the isChasing Boolean on and off in the animator depending on the player’s distance from the AI.
629
Creating Games with Unity, Substance Painter, & Maya
FIGURE 17.39 Using the Root Transform Rotation to offset the character so she is
facing forward.
630
AI
Tutorial Conclusion
This is a good place to pause, save the scene, and apply
the prefab Overrides to EllenEnemy. The core of her AI is
now complete; but she currently isn’t firing anything out
of that gun. She also isn’t taking damage and her gun
won’t deliver damage, but those are issues for another
upcoming chapter.
So, the plan for this tutorial will be to first, set up the
basic mechanics needed for firing the gun (duplicating
and editing a bullet and creating a launch point for
EllenEnemy’s gun). Then, we’ll set up a script to control
EllenEnemy’s weapon, and then create an AnimationEvent
that tells that script when to fire.
631
Creating Games with Unity, Substance Painter, & Maya
FIGURE 17.41 New material settings for the trail renderer that will follow EllenEnemy’s bullet.
632
AI
FIGURE 17.42 The exact rotation doesn’t matter (we’ll control that with script), but
the launch point out at the end of the gun will give us a good place to instantiate the
bullet from.
FIGURE 17.43 Creating the function that will fire the gun. Now we just need to decide when to fire this function.
633
Creating Games with Unity, Substance Painter, & Maya
FIGURE 17.44 Making the launchPoint look at the player when it comes time to launch a bullet. EllenEnemy’s a deadeye!
Why?
Why put it there? Why not on the gun? In actuality, it
doesn’t matter where it’s put as all the things it controls
are stored in variables. In this case, we’re putting it on the
EllenEnemy because that’s where the EllenEnemyAiScript
is at. This keeps all the scripts involved in the AI control in
one place, and puts the script on the same gameObject
that the Animator is on.
Animation Events
It is finally time for the star of the tutorial: Animation
Events. These are useful tools that allow a marker to
634
AI
FIGURE 17.45 The Events section of the Animation tab for an animation fbx.
Awkward Implementation
While Animation Events are easy to understand, the
implementation down here is a little tricky. Figure 17.45
shows the Events timeline, you can’t actually drag the
635
Creating Games with Unity, Substance Painter, & Maya
FIGURE 17.46 You can only scrub through the animation in the preview area (not in
the events area).
636
AI
FIGURE 17.47 Scrubbing to fine the frame just before the recoil.
Why?
Notice that there are some other input fields there: Float,
Int, String, Object. Those are all there in case the function
fired needs an input value. Our ShootPistol() requires
none, so these can all be left as is.
637
Creating Games with Unity, Substance Painter, & Maya
Tutorial Conclusion
And that’s it for Animation Events. There’s still lots of
refinement that we could add to this script that you
already know how to do…play a sound when she fires,
cause her to reload after she’s fired a certain amount of
bullets, even add a muzzle flash. But we’ll leave that up to
you. For now, let’s start to put everything together in the
MainLevel.
638
AI
Why?
The doors can be marked as Static for baking lighting, but
they need to be checked off as static elements when 1) we
want them to move with script and 2) when we want the
AI to be able to walk through them. If the doors were to
remain marked as Static, the NavMesh would be built with
them as barriers, and the NavMeshAgents would never be
able to cross their threshold.
639
Creating Games with Unity, Substance Painter, & Maya
Why?
So as long as the NavMesh doesn’t disappear completely
in a hallway, it will probably be alright. However, if it
ever disappears completely, that needs to be adjusted.
Otherwise, it will create a strange invisible forcefield for the
EllenEnemys NavMeshAgent that won’t be able to overcome.
640
AI
FIGURE 17.53 Potential problems as the NavMesh gets very narrow in a narrow
hallway with lots of obstacles.
641
Creating Games with Unity, Substance Painter, & Maya
Conclusion
And there it is. She walks or runs, and tries to kill you when
she sees you. This is made possible by the AI methods of a
NavMesh and a NavMeshAgent that is able to move about
upon it. We’ve looked at how to allow the animation to
define the speed of the NavMeshAgent and how to place
Animation Events within the animations. Finally, we’ve
looked at how to trigger different animation states for the
AI character so that she knows when to do what.
642
CHAPTER 18
At the end of the day, health and ammo (or any inventory)
is simply a number; usually, it’s a whole number, an
integer, and usually, it’s a positive integer. Keeping track of
health and ammo then, is simply a matter of counting—
moving up and down in whole numbers.
643
Creating Games with Unity, Substance Painter, & Maya
644
Health and Inventory
Why?
This script does a few things we haven’t done before. The
first is that after creating a variable to hold the health
value (called health), this script gives it an initial value of
100. After this code is compiled, it won’t default to 0; it will
default to 100. Notice that this method only works if the
code has never been compiled before.
Why?
This is a pretty simple script, but it’s worth breaking some
of it down. By default, OnTriggerEnter() requires an input.
The input is of type collider and named “other”; basically,
this means this function will store the collider of the thing
that triggered it in a bucket called “other”.
645
Creating Games with Unity, Substance Painter, & Maya
FIGURE 18.3 DamageBoxScript that does damage to whatever runs into its trigger.
646
Health and Inventory
FIGURE 18.4 Entering the damage box should be calling out to the
PlayerHealthScript and doing five points worth of damage every time the player
enters the box.
647
Creating Games with Unity, Substance Painter, & Maya
Why?
There are a few subtle differences between how we
did this in the DamageBoxScript, but they are worth
pointing out. Most importantly is that this script is using
OnCollisionEnter(). OnCollisionEnter() requires a different
input (a variable of type Collision called “collision”) than we
saw in OnTriggerEnter() (which required a variable of type
Collider). But the basic concept is still the same…When
whatever this script is attached to collides with something,
it will check if that something (stored in the collision bucket)
has a tag of “Player”. If it does, it will talk to PlayerHealthScript
and DoDamage(), passing a value of 10 to that function.
648
Health and Inventory
FIGURE 18.7 HealthPack prefab placed in the scene. Notice that it has an animation script (HealthPackAnimationScript) and a
Box Collider. Note that the Box Collider has Is Trigger checked.
649
Creating Games with Unity, Substance Painter, & Maya
FIGURE 18.9 Clamping the health value so that it doesn’t go over 100.
Why?
This step isn’t purely necessary if the designed game play
allows the player to supercharge their health. But in most
cases you can’t get more than 100% healthy. So, clamping
the value between 0 and 100 will ensure that the player
never gets over 100 health if they’ve taken just a little
damage and pick up a health pack.
Tutorial Conclusion
So there ‘tis. A complete health system built for the player.
Anything that needs to do damage to the player can now
just talk to the PlayerHealthScript and fire its DoDamage()
function. And health packs or health zones, or however
you wish to heal the character, is now in place as well.
650
Health and Inventory
Why?
We happen to know that Ellen is 1.6 units tall. So while we
could use the Edit Collider button to eyeball the collider in,
a Height: 1.6 and Center Y: 0.8 are pretty easy to get exact.
The Radius: 0.2 is preference. Too small, and she gets pretty
hard to hit, too big and the game gets too easy.
651
Creating Games with Unity, Substance Painter, & Maya
652
Health and Inventory
FIGURE 18.12 Creating a new Tag named “Enemy”. Note that creating it doesn’t
automatically apply it to EllenEnemy.
Why?
I know, it seems like we’ve been here before. The problem
is that when we use the Add Tag… method, it creates the
tag, but doesn’t add it to the object we started on. So
after creating the tag, you must come back and still add it
to the desired object.
653
Creating Games with Unity, Substance Painter, & Maya
654
Health and Inventory
Why?
We’re leveraging a bunch of work we did last chapter.
As a review, in the last chapter we edited the Animator
to include the Hit Reaction animation and the Death
from the Back animation. In addition, gotHit and die
were created as Trigger Parameters. Finally, transitions
were built from Any State into both Hit Reaction and
Death From The Back. Because all those animation states
are already in place, with transitions built that can be
triggered, we just need to tie into them with the code. For
a quick review, the EllenEnemyController should look like
Figure 18.16.
FIGURE 18.16 Just a review of the hard work completed in the last chapter.
655
Creating Games with Unity, Substance Painter, & Maya
FIGURE 18.17 Checking health and playing the death animation if it gets below 0.
656
Health and Inventory
FIGURE 18.19 Baking the Root Transform Position (Y) into the animation. This will cause the animation to control where it sits
in Y when it falls (and not the NavMeshAgent).
FIGURE 18.20 Deleting components and resetting triggers that are no longer needed once she plays her death animation. This
gets rid of more than needed, but it will keep unnecessary work from being done by components that aren’t needed any longer.
657
Creating Games with Unity, Substance Painter, & Maya
using UnityEngine.AI;
658
Health and Inventory
Tutorial Conclusion
Health systems really are not terribly difficult. Remember
that health is a number, and create mechanics to change
it (DoDamage() or DoHealing()), and then decide who can
talk to those functions and you’re done.
659
Creating Games with Unity, Substance Painter, & Maya
FIGURE 18.23 The variables bulletAmmo and grenadeAmmo have already been
created in PlayerControlScript (or they should have anyway). If they aren’t in yours, be
sure to create them.
FIGURE 18.24 Creating a new variable to keep track of how many bullets are left
in the clip. This will allow us to track how many bullets can be fired before reload is
needed.
660
Health and Inventory
Why?
This will overwrite some values we’ve entered for Grenade
Ammo and Bullet Ammo out in the Unity Editor, but that’s
alright. Eventually, these variables will be made private
anyway (once we have UI).
FIGURE 18.26 Subtracting one from grenadeAmmo each time the player presses Fire1 and the grenade launcher is active.
661
Creating Games with Unity, Substance Painter, & Maya
FIGURE 18.27 Checking to see if there are still grenades available before firing.
FIGURE 18.28 Adjustments to the script to reduce both bulletAmmo and bulletsInClip when pressing Fire1.
662
Health and Inventory
FIGURE 18.29 Making the BulletReload() work reset the bullets in the clip (but not the players overall bullet count).
663
Creating Games with Unity, Substance Painter, & Maya
FIGURE 18.30 The EllenGrenadeController from our earlier efforts. Hint: the problem is in the transition highlighted with the
red arrow.
FIGURE 18.31 After creating a needReload parameter, the transition from attack_
anim to reload_anim can have a new Condition created.
Why?
It’s important to notice that this Transition had not
conditions before. This meant that every time attack_
anim was done playing, it automatically shifted to reload_
anim. This was why, even though the player couldn’t fire
another grenade, the animation was still playing showing
664
Health and Inventory
FIGURE 18.32 Checking to see if there are still grenades left before deciding what animations to play.
665
Creating Games with Unity, Substance Painter, & Maya
Reloading Ammo
Believe it or not, we’ve just completed the hardest part.
Reloading the ammo will be piece of cake. The basic idea
is we will create two new scripts (one for a bulletPack and
one for a grenadePack) that, when the player runs over
them, will reach out to this PlayerControlScript and reset
the numbers for the respective ammo count.
Why?
There is nothing particularly special about these assets.
They have a custom shader on them with a Fresnel
effect for visual pizzazz. However it is important to
notice that both of the prefabs have a Box Collider that
has Is Trigger checked. I bet you can see where we’re
going with this…
666
Health and Inventory
Why?
This script already knows all the variables for the ammo
numbers. It knows who the dummyGrenade is. And it
knows the Booleans necessary to allow the guns to be
fired again. Therefore, it’s best to do all the resetting in
functions in this script.
667
Creating Games with Unity, Substance Painter, & Maya
Why?
So this is doing things we’ve seen before with one new
addition. We know what OnTriggerEnter does, and we’ve
seen the process of checking if the thing that entered the
trigger is tagged “Player”. We’ve even seen the process of
getting a script on the thing that entered the trigger. This
is very similar to our DoDamage() methods of earlier. Only
here, we’re firing a public function that resets everything
needed for the bullet ammos.
668
Health and Inventory
FIGURE 18.38 Placed health and ammo packs. Particularly look at getting them in
the armory, and just before you enter to meet the boss.
Conclusion
Only one chapter to go. At this point, we have most of the
mechanics in place. But even though the player’s health
is counting down, there’s currently nothing telling the
player that they’ve lost if their health reaches 0. This is also
the case for their ammo count. To solve these problems,
we need to provide a User Interface (UI) for the player to
provide visual feedback.
669
CHAPTER 19
UI
671
Creating Games with Unity, Substance Painter, & Maya
Screen Space
Consider the two screenshots show in Figures 19.1 and
19.2. Both of these are the same scene. In both, a Canvas
has been created for the UI. In Figure 19.1, there are three
things to note. First, the little red circle is actually the
entire 3D scene (itty, bitty, tiny). The big white square in
that scene represents the Canvas in which the UI will be
built. Notice that the shape of the big white square in the
Scene window is the same shape as the Game window.
This can be seen in Figure 19.2. As the Game window is
resized so that it’s wide and short, the Canvas in the Scene
view does the same thing.
FIGURE 19.1 A UI Canvas. Note the entire 3D scene inside the red circle, and the shape of the Canvas matches the Game window.
672
UI
FIGURE 19.2 Notice that the Game window is resized, and the Canvas is resized as well.
673
Creating Games with Unity, Substance Painter, & Maya
674
UI
Why?
Don’t delete either of these objects. The EventSystem
contains the mechanics that allow things like buttons to
work. With students, it’s very common to have them ask
about a non-working UI system and, after a long time
looking at code, the instructor finally asks, “Did you delete
the EventSystem?” “Yeah,” they respond, “I didn’t put it
there and didn’t know what it was for so I got rid of it.”
Remember, you need this object. Don’t delete it.
Why?
As discussed in the introduction, this will make sure that
the elements within this canvas get bigger or smaller
in accordance with the resolution of the player’s screen
resolution. 1920 × 1080 is 1080p and the resolution of
most folks’ monitors these days, and so it is a good place
675
Creating Games with Unity, Substance Painter, & Maya
Why?
This will see the alpha channels for all the textures and
prepare them for a lightweight implementation into Unity.
Note that they are all a very boring gray. This is by design.
In Unity, 50% gray means that we can change the color
however we desire. Pure white or pure black images are
tough to get just right, and moving an image that is (for
example) blue to red is even worse. A 50% gray image will
let us change the color to anything we want.
676
UI
FIGURE 19.5 Setting the Pivot of the Reticle to the center of the image and
anchoring it to the center of the Canvas.
677
Creating Games with Unity, Substance Painter, & Maya
FIGURE 19.6 Locking the BulletAmmo_BG to the bottom left corner of the UI.
FIGURE 19.7 BulletAmmo_BG placed in scene with assigned sprite and color
adjustments.
678
UI
Why?
It’s important to see that both of these backgrounds have
the same pivot and anchor. Because of this, the screen
size could change and these two elements would remain
at the same distance from each other. However, their
distance from the Reticle (which has a different Pivot/
Anchor) would change.
679
Creating Games with Unity, Substance Painter, & Maya
Why?
Wait a minute…didn’t we just say it was important
for the UI elements down here in the left corner to all
share the same Anchor/Pivot? We did, but by making
this GrenadeIndicator1 a child of GrenadeAmmo_BG,
the Anchor/Pivot will set a relationship to the parent
680
UI
FIGURE 19.11 Duplicating, renaming, and positioning the other GrenadeIndicators. Adjust color if desired.
Health Indicator
The UI plan here is to make a bar that sits behind the
Health_FG that will get smaller as the player’s health
decreases. There are some coding tricks we’re going to do
later that will scale that UI element. But to make the math
easier, we’re going to create a UI Panel and give it some
681
Creating Games with Unity, Substance Painter, & Maya
FIGURE 19.13 Creating clip indicators. These are also children of BulletAmmoBG.
682
UI
FIGURE 19.14 Setting pivot and anchor for HealthIndicator to bottom left.
Why?
This is not going to be a child of the Health_FG…if it
was, it would be in front (and we need it to be behind).
683
Creating Games with Unity, Substance Painter, & Maya
Why?
This seems arbitrary, but that Height: 100 is carefully
planned. Height = 100, Health = 100…see the idea? Later
when the health goes down, we’ll adjust the Height value
to match.
FIGURE 19.15 Aligning (by moving) the HealthIndicator so the bottom aligns with the bottom of the feet of the character
outline.
684
UI
FIGURE 19.16 Using Scale to make HealthIndicator the desired size without
changing Width and Height settings.
Why?
Notice that when scaling, the Width and Height settings
remain at 50 and 100, respectively. This means that our
Height = 100 is still intact and we can use it later to tie it
easily to the Health value.
Tutorial Conclusion
And with that, the UI elements are in place. The don’t do
anything yet, that is still to come in code. But the pieces
are ready to take instructions. Feel free to adjust colors as
desired, even change the overall size.
685
Creating Games with Unity, Substance Painter, & Maya
FIGURE 19.17 Changing the order in the Hierarchy changes which UI element is drawn first and which are drawn later (and
thus on top of earlier ones).
686
UI
FIGURE 19.19 Making sure this script will know how to talk to UI objects.
FIGURE 19.20 Creating variables to store all of the indicators for the bullets. The
names are arbitrary.
FIGURE 19.21 Creating variables to store the bullet clip indicators and grenade
indicators. The names are arbitrary.
687
Creating Games with Unity, Substance Painter, & Maya
688
UI
FIGURE 19.23 Function using a Switch Statement to turn UI off depending on how
many bullets are left in the clip. Notice the break part way down (it’s a long function),
but the pattern should be clear.
Why?
Notice that the last chunk of code there is:
default:
break;
689
Creating Games with Unity, Substance Painter, & Maya
FIGURE 19.24 Telling the script to fire the UpdateBulletUI() function when the
bulletsInClip amount changes.
690
UI
FIGURE 19.27 Checking to see how many bullets are left, and based on that
number, turning off the resulting clip UI.
691
Creating Games with Unity, Substance Painter, & Maya
FIGURE 19.28 Turning the clip indicators back on when the character has loaded
up on ammo.
692
UI
FIGURE 19.30 Updating the grenade indicator UI whenever the number of grenades
change.
FIGURE 19.31 When new grenades are picked up, the UI indicates it.
Health UI
Thus far in this tutorial, the process has been switching
UI images on and off by enabling/disabling the Image
component. But UI can be manipulated in many more
ways. Although we won’t deal with it here, UI can have
its material adjusted, it can be animated, and it can have
animated masks (just to name a few of the things it
can do).
693
Creating Games with Unity, Substance Painter, & Maya
FIGURE 19.32 Storing the RectTransform that will be adjusted when the health
changes.
Why?
Yes, we could be storing healthIndicator as a GameObject,
or as an Image, or as a host of other things. But by storing
it as a RectTransform, we can save quite a few keystrokes
later when using RectTransform.sizeDelta.
694
UI
FIGURE 19.34 Updating the Height of the HealthIndicator when health goes back
up as well.
FIGURE 19.35 On the losing side of a fight with EllenEnemy. As health goes down in
the script, the UI changes to alert the player.
Tutorial Conclusion
That’s it. Once the UI has been set up, tying things
together so that numbers actually affect the UI is not
difficult, if the developer can just track down when the
numbers change. Once that’s understood, the UI can be
695
Creating Games with Unity, Substance Painter, & Maya
But that’s not all. Coming up, we’ll start to use UI to create
buttons and move between levels.
696
UI
FIGURE 19.37 Using an imported image to define the regular state of a button.
Why?
The default mode for Transition is Color Tint. This can
work fine as it will change the color of the button as the
mouse moves over the button, or the player clicks it. But
we have prepared other versions of the button to control
these states. These will allow for a more sophisticated
visual effect.
Step 10: Test. Play the game and click that button to
see how the sprite states work.
697
Creating Games with Unity, Substance Painter, & Maya
698
UI
FIGURE 19.39 Rect Tool and the handles created to adjust the text box.
699
Creating Games with Unity, Substance Painter, & Maya
FIGURE 19.40 Moving the StartButton over to allow for other text.
700
UI
FIGURE 19.43 Providing instructions on how to play for the player. Adjust to taste.
Interactive Buttons
Up to now, we have been leveraging the built-in
components of the UI Button. There are two parts to each
by default: the graphical element, and the Text overlaid on
that button. The text can be deleted altogether if desired.
The graphical part of the button has several components
built in. We’ve already looked at the Image section, and
have interacted a bit the Button part (Figure 19.44) – this
is where we defined the various states of the Sprite Swap.
However, the important thing now is at the bottom of the
Button component: On Click().
701
Creating Games with Unity, Substance Painter, & Maya
FIGURE 19.44 In order to load different levels/scenes in Unity, we must use the
SceneManagement library.
Why?
In both of these situations, this only works if the functions
are public (which both LoadMainLevel() and QuitGame() are).
702
UI
FIGURE 19.47 Making the StartButton fire the LoadMainLevel function in the
MenuInteractionScript when it is clicked.
Why?
In Unity’s vernacular, a “Build” is the actual game that a
player would play. It will contain the executable and all
other needed files to run the game. The Build Settings
window allows developers to decide which platform
to build to (bottom left) and which Scenes to actually
include. If this isn’t filled out to include MainLevel, then
the LoadMainLevel() function would not work.
703
Creating Games with Unity, Substance Painter, & Maya
FIGURE 19.48 Assigning the levels created that should be included in the build.
FIGURE 19.49 Creating a build. This can take a little while, so take a break.
704
UI
Why?
Application.Quit() can only be tested on a build. So in
order to make sure that Quit button works, a build has to
be output.
705
Creating Games with Unity, Substance Painter, & Maya
FIGURE 19.50 The LoseLevel. No new coding needed here, just a rearrangement of
UI pieces.
FIGURE 19.51 The WinLevel. No new coding need here, just a rearrangement of UI
pieces.
706
UI
FIGURE 19.52 Make sure that IntroLevel is first. But after that, just ensure that all the levels are part of the Build Settings.
FIGURE 19.53 Adjustments to make sure the game is over when health drops below 0.
707
Creating Games with Unity, Substance Painter, & Maya
Conclusion
And suddenly we have a game! Almost. Currently, there is
a lose state, but no way to win. In the next chapter, we will
build the final boss battle and make sure that the security
cameras work so the player has a way to win.
708
CHAPTER 20
Boss Battle
709
Creating Games with Unity, Substance Painter, & Maya
Why?
Ideally, all the geometry comes from the modeler all set
up for animation, or coding. But usually the modeler
doesn’t know the final use of the model, and it’s really
beyond their concern. So, it is not unusual to receive
710
Boss Battle
Why?
Why the hero_cable_sphere? At the top of the Unity
interface is the ability to change whether Unity is showing
the axis of a selected object at its Pivot or Geometric
Center (Figure 20.3). We have looked at this briefly before,
but here it is especially important. This needs to read Pivot
(click it if it reads Center). Regardless of where Unity shows
the pivot (in the case of showing the handle at the Center),
711
Creating Games with Unity, Substance Painter, & Maya
FIGURE 20.2 Creating a simple rig by making objects a child of an object with the axis in the right place.
the actual pivot of the object (and the point around which
Unity rotates an object) does not change. If the gizmo is
displayed at the actual pivot, you can see where script
FIGURE 20.3 There are times when
would actually rotate the object.
showing the gizmo at the geometric
center is useful, but when trying to find With the gizmo showing the actual pivot of objects,
its actual rotation point, make sure the move through the different parts of the hero. Most of the
gizmos are set to show the actual Pivot. objects have their pivot in a spot that isn’t centered at the
middle of the bigger sphere shape. The one that does is
hero_cable_sphere. So, quickly making everything a child
of that object makes sure that all of the top part of hero
rotates around an appropriate pivot.
712
Boss Battle
Why?
The first part of the script should look familiar. It creates
three variables, the first to store who the player is (that we
populate in the Awake() function), the second to store a
number (a float) called followSpeed that we give an initial
value of 3 to (although this could be changed later), and
the last to store where the rotation should happen from.
Then in the Awake, we populate the player variable and
the rotationPoint.
After that, lots of new things happen. First, notice that
we have a function called FixedUpdate(). FixedUpdate()
happens every frame, but happens after Unity has
calculated all the commands that are part of Update() in
this or other scripts. By using a FixedUpdate() method,
we can be sure that this code is being sure to know
where the player is before starting to calculate where
to work.
713
Creating Games with Unity, Substance Painter, & Maya
714
Boss Battle
FIGURE 20.5 With the new FinalBossScript, hero should rotate to follow the player.
FIGURE 20.6 Creating a new grenade launch point and ensuring it is appropriate in
the Hierarchy.
Why?
Although we could make the grenade script ignore the
collider of the hero, it’s easier to reuse the same script, and
simply make sure that the grenade (that we’re about to
instantiate) is created outside the sphere to begin with.
715
Creating Games with Unity, Substance Painter, & Maya
FIGURE 20.7 Creating necessary variables for the grenade launching process.
Why?
While loops perform work as long as a condition is
met. In this case, while(gameObject) means: “While this
gameObject exists, keep doing the work in my curly
brackets.” The work contained in those curly brackets
should look familiar as it was copied/pasted from the
player’s grenade launcher mechanism. Then, the line to
wait 3 seconds is added as the last part of the work to do.
FIGURE 20.9 Temporarily allowing the Boss to fire grenades right way.
716
Boss Battle
FIGURE 20.10 Creating a public function that will actually start the boss firing rockets.
Why?
For testing, having the boss firing grenades at the start
of the game works fine. However, when this game really
starts, the boss shouldn’t be firing rockets every 3 seconds
at the player when they are on the other side of the
facility. This should only happen when the player walks
into the FinalBossRoom.
717
Creating Games with Unity, Substance Painter, & Maya
FIGURE 20.11 Trigger at the entrance to the FinalBossRoom that will start the boss
firing.
FIGURE 20.12 Creating a trigger script so that when the player enters the room, the
boss gets busy and starts firing.
Why?
Probably you’ve noticed by now that even if the boss is
firing grenades at the player, the player currently takes no
damage. This is because up to now, only the player could
fire a grenade, and the grenade doesn’t know how to do
damage to the player yet. This will be fixed in a second,
but first let’s build a health script for the boss.
718
Boss Battle
Why?
Without a collider, this boss won’t know when it’s been hit
by the player’s grenades or bullets.
719
Creating Games with Unity, Substance Painter, & Maya
FIGURE 20.14 Creating the start of FinalBossHealthScript. Notice that the comments
are leaving notes on what this will do in the future.
Why?
Couldn’t this be done more elegantly? Heck yes. If the
enemy, boss, and player shared the same healthscript, it
wouldn’t take quite so many lines of code here. However,
in a learning situation where we are layering one idea
on top of another, this sort of clumsy approach here is
necessary. Later, as you build your own games, you will
find efficiencies we have not taken advantage of here.
720
Boss Battle
FIGURE 20.16 Adding the ability to do damage to both the Boss and Player.
721
Creating Games with Unity, Substance Painter, & Maya
Step 24: Test and see if the player can lose and
the boss take damage. At this point, the
grenades launched from the boss should
explode when they hit the player and do
damage. Pretty quickly, the player should lose
the game. Similarly, select the hero so that
the FinalBossHealthScript can be seen in the
Inspector. As the player hits the boss with bullets
or grenades, the health value should go down.
Why?
A Render Mode of World Space means that this UI isn’t
locked into the screen space but rather exists in the 3D
space of the game. This means it can (and needs to be)
moved and scaled into place as it will remain locked to a
location in 3D space.
722
Boss Battle
FIGURE 20.18 Setting the new Canvas to exist in World Space (not screen space).
Why?
You can probably guess why we’re doing this, but the
idea here is to make sure that the Width value is the same
as the health value of the boss. This will make resizing
the bar a simple matter. Notice that we are leaving the
Anchor/Pivot at middle. This will make the progress bar
scale from the middle (not an end).
Step 29: Move and scale FinalBossUI_Canvas into
place in from of the boss. Remember, this time
use the Move (W), Scale (R), and Rotate (E) tools
723
Creating Games with Unity, Substance Painter, & Maya
FIGURE 20.19 Setting up some easy-to-manipulate Width and Height settings for
the FinalBossUI_Canvas.
724
Boss Battle
FIGURE 20.21 Adjustments to the UI Panel to give a bit o’ glow to the Panel.
FIGURE 20.22 Tying the Width of FinalBossUI_Canvas to the health of the boss.
Final Theatrics
At this point, the game knows what to do when the
player’s health is 0 or less (it shows LoseLevel). Now we
need to build in the ability to win the game – which will
happen when the boss’ health is 0 or less. To add some
excitement to this, we’ll make the boss break up with
some explosive force.
725
Creating Games with Unity, Substance Painter, & Maya
Other than the inner sphere, the hero asset has been
separated into its separate shapes and moved so that they
aren’t overlapping. This will keep errors from happening
when we apply physics to all these shapes. Feel free to
take a look at the file from the support files if interested.
The plan is that when the hero’s health is 0 (or less), we
will swap out this version of the hero with all its separated
parts. We’ll give a bit of explosive force and watch all the
parts fly off.
726
Boss Battle
727
Creating Games with Unity, Substance Painter, & Maya
FIGURE 20.25 Setting up the parts of DestructedHero to all have Mesh Colliders and
Rigidbodies.
FIGURE 20.26 Swapping out the destructed version of the hero when its health is
0 or less.
728
Boss Battle
FIGURE 20.29 Allowing the BossHealthScript to fire the GameOver function in GameOverScript.
Why?
We haven’t used GameObject.Find(“Name of Object”)
very often. It can be expensive to have the game search
the entire level for an object by name. So we’d never (for
instance) have this in an Update() function. But in this
case, since it’s only going to happen once, it makes things
pretty speedy to write this sort of code.
729
Creating Games with Unity, Substance Painter, & Maya
Why?
The FPSController hides and locks the mouse. Without
unlocking and showing it when the Game Over screens
appear, it remains hidden and the player is unable to click
any of the buttons.
730
Boss Battle
FIGURE 20.31 Unlocking and showing the cursor for the GameOver scenes.
Conclusion
Of course, there are lots of other things that can be done
to help make this final scene more climatic. Figure 20.31
shows an adjusted version of the GameOver script that
includes shaking the camera, and a whiteout.
731
Index
Note: Italic page numbers refer to figures.
733
animation events/working weapon (cont.) swapping to animation mode 503, 504
creating function to fire 633, 634, 632–634 warnings and errors 507
launch point 632, 633 balance 709
new material settings 632, 632 balance skin variation 327, 328
tools 634 base color, PBR 99
application programming interface (API) base floor creation 44–54, 45–47, 49–54
defined 498 belt, character modeling 287, 288
instantiation 498–499, 499, 500 belts, straps, pockets, holster, and boots
scripting reference 498 353–354, 353, 354
area light 215, 215, 229, 229 bevel command 288, 289
arm controls set up bevel tool 9, 10
rigging 400–402, 400–402 binary system 43
arm joints creation 376, 376, 377, 378 binding joints 400
asset movement process 148 bind skin 391, 392
atlas 74 blending mode, definition 101
attack animation 431–433, 432, 433 blendshape 296
Autodesk Maya 1 body, character modeling 268–273, 268–273
automatic UV 89 body adjustment, character modeling 292, 293
auto rigging Boo 466
adjusting base map color tints 453, 453 boots, character modeling 287, 288, 289
Mixamo 443–449 boss battle
placed scene with cheater light 451, 451 added sphere collider 719, 719
plugged textures to create materials adjusting BulletScript 720, 721
451, 452 assigning and creating tag 719, 720
setting up animator 454–464 creating loop 715, 716
setting up subsurface scattering, skin creating simple rig 711, 712
shader 451, 452 creating variables 715, 716
substance painter output 449–450, 450 final boss 710–722
subsurface scattering effects 452, 453, 453 FinalBossScript 713, 713, 714, 715, 719, 720
final theatrics 725–730
baked mesh data 101 FixedUpdate() 713
Bake pivot 366 grenade launch point 715–716, 715
baking 93, 97–98 health bar 722–725
camera adjustments and postprocessing multitude skills 710
236–241, 236–240 pivot/geometric center 712, 712
character texturing 322, 322, 323 prefab editor 710, 711
error 322 public function 717, 717
expensive calculations 233 temporarily allowing boss 716, 716
hallway prebaked and postbaked 235, 236 trigger 717, 718
lightmap information 233 unlocking and showing cursor 731, 731
quick settings 234, 235 box modeling 7, 245
setting lights in each prefab 233, 234 bridge tool 25
baking animation keys brush, short cuts to tweak 103–104
constraints 505, 506, 506 built-in functions 467–468, 483, 483
culling process 508
deletion 506, 507 C#
game engine 507 addding script to scene, after compiling
rig-centric tools 503 475, 476
setting rotation keys 503 API 498–500
simulation options 505, 505 class declaration 467
734
comments 467 hands 274–281, 274–281
DOTween 486–488 head 262–264, 262–264
empty script example 466, 466 image plane setup in Maya 245–247, 246
HelloWorldScript creation 474, 474 internal structures 267, 267
libraries 466 mouth 261, 261
methods/functions 467–468, 469 neck 265, 266
pinned console 473, 473 nose 256, 256, 257, 258, 258–259, 260, 260
print command to Update() 477, 477 outer garment base 285, 286
print line of code, fired every frame 477, 477 polycount 245
syntax 469–470 preview materials 286, 287
undisputed preferred language 466 style sheet 244
Unity and visual studio 470–472 sweater 284, 285, 285, 286
variables 489–498 watch 290, 292
cables base material 121, 121, 123 watchband 292, 293
camera configuration 418–421, 418–419 weapon 292–294, 293, 294
camera extras workflow 245
adding spotlight 553, 554 character rig 414–415
build the code 557, 558 characters making 243
closed-circuit 553 character texturing 321–323
color attribute 556, 557 baking 322, 322
DefaultRenderTexture 556, 557 error 322
extracted monitor screens 554–555, 555 belts, straps, pockets, holster, and boots
mechanics 553 353–354, 353, 354
placed cameras 558, 559 chest logo 363, 364
placing screen object 556, 556 export 322–323
prefab, placed and configured 558, 559 Export Textures 365–367, 366, 367
process, Maya 555–556 eye 333–340, 335–341
rendering 554 gloves 354–360, 355–360
Canvas Scaler 673, 675 gun 363, 364
carbon fiber 124, 125 hair 331–333, 331–333
Center Pivot 40 import the model 322
Change Pivot 40–41 leather material 353, 353, 354
Channel Box 8, 8, 9, 27, 389 metal bolts 365, 365
input stack of 15, 17 pants 348–352, 349–352
Channel Box editor 424, 434 skin texturing 323–329, 324–329
character, gaming 243 upper body 340–347, 342–348
character modeling 243, 297, 297 watch 361–362, 362
belt 287, 288 character UV mapping 300
body 268–273, 268–273 body 302–308, 303–308
body adjustment 292, 293 cleanup process 302
boots 287, 288, 288, 289, 289, 290 eye 308–309, 309
clean up 295, 295, 296, 296 garment 312–319, 313–317
concept art 244, 244 hair 309–311, 310, 311
ear 264–265, 264–265 mesh inspection 300–302, 301, 302
eyeball 247–249, 247–249 Checker Map 318
eyelids creation 249–253, 250–252, 253 checker texture 58, 59, 60
eye socket creation 253, 254, 254, 255 chest logo, character texturing 363, 362
forehead 257, 257 chest weighting 394, 395
gloves 289, 290, 291 Circularize Components 21
hairs 281–284, 281–284 class declaration 467
735
clavicle and body controls 406–409, 406–409 overrides 228, 228
clavicle and shoulder joint 377, 377 placed area light 229, 229
cleaning up odd jitters 428 prefab editor 231, 231
cleanup process shadow casting effect 223
character modeling 295, 295, 296, 296 spot light 227, 227
character UV mapping 302 copying, skin weighting 397–400
click-dragging 422 Create Cables or Pipes 34–36, 34–36
clipping planes 553 curvature generator 120, 120
color distribution 323, 324–325, 325–326 curve tool 51–52
color setting 117 cutting process
color variation 327, 328 UV mapping
Combine and Separate 33–34, 33 hide the seams 316
Combine command 33–34 stretching 316
comments 467 texel density 316
Component Editor 395, 397 cut UV 62, 62
concept art 244, 244 CV see Control Vertices (CV)
constrains 402
controlling animations dark metal material 97, 100, 102
creating transition 518, 519 decimal system 43
defining transition 520, 519 default blending mode 101
placing an animation clip 517, 518 Delete Edge command 27, 30
plugging Animator Controller 517, 517 deployment strategies 135
visual graph-making and coding 516 directional light 183, 212–213, 213, 232, 232
controlling animator with code Display Layer Editor 415
animation ranges 529, 529 display layers 415–418, 416–417
applying changes to FPSController 529, 529 dot syntax 469
creating and populating variables 522, 523 DOTween
creating boolean 524, 524 adding libraries 488, 488
creating pathways 524, 525 documentation 488
defining situation 526, 527 setting up 486, 487
Input Manager 521, 522 starting setup 486, 487
pseudocode 521 tweening tools 486
script listen (every frame) 520, 521 driver joint chain 400
swapping 529, 531 Duplicate Faces command 16
transition settings 524, 525, 525, 526 Duplicate Special 39, 39
triggering 523, 523 Duplicate with Transform 38–39, 38–39
turning booleans on and off 526, 527, 528
updated script 529, 530 ease-in’s and ease-out’s 429, 431, 432, 434
Control Vertices (CV) 34, 34 edge 4
cookies flow 257
adjusted emissive color 230–231, 232 ring 10
applying changes, instances of prefab variation 344, 345, 346
227, 228 edgewear effect 108, 112, 112
directional light 232, 232 Ellen_full_body_ref 392, 397–398
emissive shaders 231, 232 Ellen_sweater_geo 398
first pass at area lights 229, 229 emission intensity 183–184
IES 224 emissive channel 129, 131
images 224 exhale moment
import settings 225–226, 226 idle animation 427, 428
increasing Texture Atlas 224–225, 225 Export Textures 365–367
736
move the gun to origin 366–367, 367 save files 415
testing 366–367, 366 two-handed weapon setup 424–427, 426
Extract Faces 33 walk animation 433–434, 436
extrude along a curve 37, 37, 38, 52 weapon movement 422–424, 423, 425
extrude tool 11, 11, 13, 13, 14, 15 FK see forward kinematics (FK)
eye, UV mapping 308–309, 309 FK arm setup 402
eyeball, character modeling 247–249, 247–249 flipped faces 300
eye-catching visual 1 floor scratches 100, 101
eyelids creation, character modeling 249–253, foot controller 390
250–252, 253 foot hierarchy setup 390–391
eye socket creation, character modeling 253, foot roll rig 387–390, 389, 390
254, 254, 255 forehead, character modeling 257, 257
forward kinematics (FK) 424
face 4–5 4096 × 4096 (4k) textures 96
facial expression rig 296 4k (4096 × 4096) texture 74
fill layer 103 FPS animation see first-person shooter (FPS)
final theatrics animation
adjustments to GameOver script 730, 730 FPS_Cam viewport 418, 419, 419, 424
allowing BossHealthScript 729, 729 Fragment Shader 2
deconstructed version 726, 726 frame-miss 569
destructed version falling apart 727, 728 frame rate 427, 427
explosive force 725 Freeze Transformation 30
FPSController 730 full-body joint skin weighting 396, 398
GameOverScript 728, 729
mapping existing materials, imported FBX game animations 420–421
726, 727 game engines 128, 133–134
setting up parts 727, 728 garment, UV mapping 312–319, 313–315, 317
shatter plugins 725 generators 100, 101–123, 102, 104, 105–121
swapping out destructed version 727, 728 geometry errors 42–43
finger controls 405, 406 gizmos 3
finger joints 379, 380, 380, 381, 382 glass materials 126, 126, 127, 128
fingers duplication 380, 381, 381 gloves
first-person shooter (FPS) animation 413–414 character modeling 289, 290, 291
attack animation 431–433, 432 character texturing 354–360, 355–361
camera configuration 418–421, 418–420 “gobo” 223
character rig 414–415 “Got Caught” animation 434–438, 436, 437
cleaning and preparing files 502 Grab and Smooth sculpting 263
cleaning up odd jitters 428 grab tool 281
display layers 415–418, 416–417 Graph Editor 429–431, 430, 438
ease-in’s and ease-out’s 429, 431 graphical user interface (GUI) see user
frame rate 427, 427 interface (UI)
game animations 420–421 Graphic API 2
“Got Caught” animation 434–438, 436, 437 grenade launcher
Graph Editor 429–431, 430 activeWeapon 565, 566
idle animation 427, 427–428 adding Capsule Collider 567–568, 568
Kassandra's animated files 502 adding variable 570, 570
pose creation 421–422 Animator Controller 564, 565
preparation (see Maya animation creating and positioning,
preparation) GrenadeLaunchPoint 569, 569
reload animation 438–439, 439 creating string variable 565, 565
737
grenade launcher (cont.) high-definition render pipeline (HDRP) 92–93,
float variable 571, 571 135–136
FPSController 564, 564 high dynamic range images (HDRI) 217
HDRP 562
instantiation 570, 570, 571, 571 IDE see integrated development
line at Start() 566, 566 environment (IDE)
populated variables 570, 570 idle animation 420, 427–428, 428
pressurized steam effects 563, 563 IK see inverse kinematics (IK)
reworking 566, 566 IK arm setup 403–406, 403, 404, 405
Rigidbody component 568, 568 IK handle 385, 386, 387, 388, 403
rising steam 563, 564 Illuminating Engineering Society (IES) 224
separating, structure of FPSController image plane setup in Maya 245–247, 246
567, 567 inhale moment, idle animation 427, 428, 429
smart 573–581 instance 39
tracking down 567, 567 integrated development
using participle effects 563, 563 environment (IDE) 470
velocity magnitude 571, 573 internal structures, character modeling
grenade launcher and pipe 440 267, 267
grid 44, 44 inverse kinematics (IK) 383, 385, 386, 424
Grow Selection 32–33
Grunge Leak Dirty 99 joint behavior 370, 370–371
gun joint chain creation
character texturing 363, 364 rigging 371–374
joint 410 neck 373, 374
root and spine joints 372, 373
hairs joint orient 376, 380
character modeling 281–284, 281–284 joint placement 371
character texturing 331–333, 332–333 left arm 374–382, 375–382
UV mapping 309–310, 310–312 joint setup
hands, character modeling 274–281, 274–281 legs 383–387, 384–387
HDRP see High-Definition Render right arm 382–383, 383
Pipeline (HDRP)
head, character modeling 262–264, kitbashing
262–264 building out extended floor 188, 189
head skin weighting 393, 393, 394, 395 building up walls 186, 186
health bar 722–725, 723–725 built platform with stairs 192, 192
health indicator catwalks and stairs 196, 197
adjusted color 685, 686 combinations of modules 194, 195
aligning/moving 684, 684 complicated module collection 193, 193
changing the order 685, 686 creating roof 196, 196
desired size, using scale 684, 685 creating small armory 194, 194
measurements 683 dressed hallways 188, 188
setting pivot and anchor 683, 683 dressed out CameraRoom 193, 193
healthValue 643 dressedStorageHangar 197, 198
heel controller 390 duplicating hall module 187, 187
height map, PBR 99, 111 filling in ceiling with floor prefabs 186, 187
hero assets 54 finishing out room 191, 191
Hide Model 41 hallway module 185, 186
hide the seams, UV mapping 316 leveraging effective grouping 190, 190
738
placed monitor 192, 193 camera exposure 218, 219
pre-built curved wall modules 188, 189 challenge 241, 242
process 185 cookies 223–232
putting ceilings 188, 189 cubemap asset 217, 218
roughed out CameraRoom 191, 191 description 209
StorageHangarEntry 194, 195 directional 212–213, 213
StorageHangar floor mapped out 194, 195 dirty volumetric and big rings 221
utilization 193, 194 hardware-driven 210
variations 190, 190 HDRI-based skies 217, 217
high-end software rendering solutions 210
labor-filled process 135 mixed 211
Lamina faces 43 physical-based rendering techniques 136
layers, Substance Painter UI 97 point 213–214, 214
layout postprocessing effects 216
adding extra visual interest 176, 177 power of prefabs 219–223, 220–224
adding trim 176, 178 real time 210
creating ceiling 182, 182 rendering calculations 210
defined 171 spot 214, 214–215, 221, 221, 223, 224
door frames 181, 181 lighting probes 241–242
dressed set 184, 184 light intensities 165
duplicated and snapped prefabs 175, 175 linear interpolation 714
ensuring glass prefabs 182, 182 Locatorleftparent 1 435
filling in corners 179, 180 locators 419
geometric center of objects 178
kitbashing 185–198 manipulation tools, translation 3–4
level flow 172 Map Size section 72
light streaming 183, 183 Mari 61
project settings 173, 174 marking menu 4, 8, 26
roughing out door and windows 180, 180 Mask Editor 101
snapping 176, 177 material adjustment
volumes 174 adding finished lights to hallway 168, 169
wall placement 179, 179 adjusted shader 168, 169
leather material, character texturing 353, 353 adjusting camera 159, 160
left arm joint structure 374–382, 375–382, adjusting intensity of point light 165, 165
405, 405 auto exposure 159
left clavicle skin weighting 396, 399 changing transparent shader 166, 167
left foot controller setup 390, 390 duplicating floor to make ceiling 162, 164
left foot rig setup hierarchy 390, 391 emissive surfaces 159
leftHand_locator 435 hallway created by duplicating section
left leg joint structure 385 164, 165
legs joint setup 383–387, 384–387, 388 measuring light intensities 166
lerp 714 move/translate tool and snapping 162, 163
levels, texturing 122–129, 123–129 moving duplicated floor 161, 161
libraries 466 rotating placed wall module 162, 163
light direction 97–98 tracking down glass material 166, 166
lighting transparency inputs 166, 167
area 215, 215 unconvincing light 168, 168
artistic functions 205 vertex snap method 161, 162
baked 210–211 virtual environments 159
739
material assignments, UV mapping 318, 320 rules
material distribution, UV mapping 319, 319 polycount 6
Maya animation preparation size and proportion 7
activating outliner 503, 503 topology 6, 6
adjusted positioning 512, 512 security camera modelling 7–32, 8–13,
baking keys 503–508 15–29, 31
controlling animations 516–520 3D model 3
controlling animator with code 520–531 translation 3–4
creating attack_anim animation clip user interface 2, 2
516, 516 maya/substance painter, exporting asset
delete unseen geometry 503, 504 asset movement process 148
extracting materials 510, 511 extracting materials 150, 151
idle animation clip, defining 515, 515 geometry imported 146, 146
imported clips 516, 516 marquee select geometry freeze
importing and adjusting rigs 514, 514 transformations 145, 145
materials adjustment 510, 511 normal maps 149, 150
near clipping plane 513, 513 NormalTexture 149
newly created Avatar 514, 515 shaders 147
substance painter output 508–510, static meshes 144
509, 510 templates 148
Maya modeling textures 147, 148
anatomy mesh inspection, character UV mapping
edge 4 300–302, 301, 302
face 4 metal bolts, character texturing 364, 365, 365
normal 5 metallic, PBR 99
object mode 5 Metallic Grate Wide 99
vertex 4 metallic roughness 92
assignments 41–42, 42 methods/functions 467–468, 467
base floor creation 44–54, 45–47, 49–54 middle line problem 302, 302
commands mirror 39, 40
Center Pivot 40 mirroring, skin weighting 397, 399
Change Pivot 40–41 mirror joints 382–383, 383
Combine and Separate 33–34, 33 mirror plane, position 108
Create Cables or Pipes 34–37, 34–36 Mixamo
Duplicate, Duplicate with Transform defined 443
38–39, 38–39 download settings for Unity 448, 449
Duplicate Special 39, 40 extract materials 449
Extract Faces 33 facial animation tools 443
Extrude Along a Curve 37–38, 37–38 FBX 2013 444, 445
Grow and Shrink Selection 32–33 grab FBX files 448, 449
Hide Model 41 gun exporting 445
mirror 39, 40 imported version of character 445, 446
Snapping 41 login and use Characters link 445, 446
View Control 41 motion-capture clips 464
geometry errors 42–43 pistol/handgun locomotion pack 447, 447
grid 44, 44 placing markers 447, 447
modular set pieces 43 sending EllenEnemyfbx 445, 446
navigation 1–2, 2 UVed version of Ellen 443, 444
normal 5, 6 Mixamo-exported MoCap animations 502
rendering 2–3 Modeling Toolkit 21, 22
740
models arrangement 94, 95 one-man-army approach 108
modular pieces, texturing 94 opacity channel 126, 127, 127
export models 94, 95 opening doors
import to Substance Painter 95–96 adding Box Collider component
models arrangement 94, 95 479–480, 480
modular set pieces 43, 52, 53, 53, 54 adjusted collider 480, 481
motion capture (MoCap) 442, 443–449, creating a floor 478
444–447, 449; see also auto rigging deleting unneeded functions 482, 483
motion trail 436, 437, 437, 440 placed Box Collider 480, 481
mouth, character modeling 261, 261, 267, 267 placed door prefab 478, 479
move tool 13, 14, 15 placed FPSController 478, 479
Multi-Cut tool 21, 22, 260, 268, 269, 274, 278, size and shape of collider 480, 481
279, 290, 301 trigger 480
multiple texturing files 95 Optimize command, body UV 305, 306
multiply blending mode 101, 102 orange panels 118
orient constraint 402
navigation 1–2, 2, 97 orient UV 64, 65, 65
navigation mesh (NavMesh) origin 2
adjusting base offset 617, 618 outer garment base, character modeling
adjustingNavMeshAgent 615, 616 285, 286
AI mechanism 605 outer shell 16, 17
Animator Controller 615 Outliner 31, 418, 423, 426
changing triggers and Booleans 626–630, overlapping faces 301, 301
626, 627–630 overshoot pose 436
creating boolean 619, 619
default NavMeshAgent 615, 616 painted approach 115–116, 114
magically floating 617, 617 painter texture outputs 450, 509
measurements 615, 617 painting skin weights 391–396, 393–396
mechanics 614 panel, Substance Painter UI 97
placing animations in animator 621–626, pants, character texturing 348–352, 349–352
622–626 parenting 31, 32
preparing FBX animation files 619–620, perspective view, image planes 246
620, 621 Per Vertex Algorithm 356, 356
NavMeshAgent 605 photogrammetry 207, 207
neck physically based camera systems 136
character modeling 265, 266 Physically-Based Rendering (PBR) 92–93
joint chain 373, 374, 375 material channels 98–100, 100, 101
neck skin weighting 393, 394, 394 pipe material 125, 126
N-gon 20, 20, 21, 43 pivot positioning 45
mesh inspection 300–301, 301 pixels 65
non-manifold geometry 42 planar projection 63
non-playable characters (NPCs) 603 player health script
normal detailing 109, 111 adjusted BulletScript 647, 647
normal map, PBR 99, 111–112, 112 basic structure 644, 644
nose, character modeling 256, 256, 257, 258, clamping health value 650, 650
258–259, 260, 260 collision 648
nostrils internals, character modeling 267, 267 damage box, testing purposes 645, 646
NURBS 34, 35, 35, 36, 37, 388, 416, 417, 425 DamageBoxScript 645, 646, 648
DoDamage() function 645, 646
Object Mode 5, 31 DoHealing() function 648, 648
741
player health script (cont.) problem, weapons system 596, 597
HealthPack prefab 649, 649 projectile weapons 600, 601
HealthPackScript 649, 650 public variable 546, 546
pod model, UV 74–89, 75–89 RaycastSource 545, 545
point light 164, 165, 203, 203, 213–214, 214 reports back 548, 548
pole 247 results in game window 596, 596
polycount 6, 27, 245 rotating weapon 598, 598
reduction methods 27, 28, 29, 29 smart camera 551, 551
polygon 2 334 supersonic weapons 544
Polygon Fill tool 116, 117 raytracing
post script animating the camera 534–544
daytime lighting 206, 206 description 533–534
lighting schemes 205 referencing character rigs 414–415
photogrammetry 206, 207 referencing process 372
terrain 206, 207 refine hand topology 278, 279
power of prefabs 219–223, 220–224 refraction model 166, 167
Prevent Negative Scale setting 25 reload animation 438–439, 439
preview materials, character modeling 286, 287 Reload Reference 414
primitive polygons 14 renderer 2
procedural texturing 102, 334 rendering process 2, 6, 20
proportion, 3D modeling 7 reticle 419, 420, 420
assigned sprite and color adjustments
quad 3, 6 677, 678
Quad Draw Tool 250 bullet indicators 681, 682
boots pattern and belt 287, 289 Canvas Scaler settings 675, 675
eyebrow 284 creating and placing GrenadeIndicator 1
eyelids creation 249, 250 679, 680
gun holster 294 creating clip indicators 681, 682
hair 282 creating Health_FG UI element 679, 680
outer garment base 285 duplicating, renaming and positioning
681, 681
RaycastHit 544 establishing, Canvas and EventSystem
raycasting 531, 571 674, 675
accuracy 593–600 locking 677, 678
adjusted ReticleUI 596, 597 offsetting 679, 679
altered script 549, 551 setting pivot 676, 677
animated camera in action 548, 550 re-topologizing tool 250, 251; see also Quad
applying changes 551, 552 Draw Tool
assigning FPSController 549, 550 retopology 281, 285
build, playground 545 returning 468
concept 544–545 reverse-engineering 731
console (every frame) 548, 549 rigging 244, 369, 410, 411
creating UI image 594, 594 arm controls set up 400–402, 400–402
creating variable 599, 599 clavicle and body controls 406–409,
diagram, centered reticle and projectile- 407–409
based weapon 596, 597 constrains 402
LineDraw 548, 548 final hierarchy 410, 411
mechanics 547, 547 finger controls 405–406
placing ReticleUI in screen 594, 595 foot hierarchy setup 390
pointing launch points 600, 600 foot roll rig 387–390, 390
742
gun joint 410 shifting to idle animation 458, 459
IK arm setup 403–405, 403–405 shooting animation 461, 462
joint behavior 370, 370–371 Shaded viewing mode 303
joint chain creation 371–374 shader 92–93, 126, 128, 129, 130, 131
neck 373, 374 shape
root and spine joints 372, 373 Maya model 22, 24
joint placement 371 shape evolving 292, 293, 293
left arm 374–382, 375–382 Shift-click trick 346, 359
joint setup Shirk Selection 32–33
legs 383–387, 384–387 size, 3D modeling 7
right arm 382–383, 383 skinned mesh renderer 460
skin weights 391, 392 skin texturing 323–330, 324–330
copying 397–400 skin weighting
mirroring 397, 399 rigging 391, 392
painting 392–396, 393–398 copying 397–400
right arm joint setup 382–383, 383 mirroring 397, 399
root and spine joints 372, 373 painting 392–396, 393–398
root_motion joint 391 smart grenade
root transform rotation 620, 628, 630 creating code 573, 573
rotate tool 18 creating variable 575, 576
roughness, PBR 99, 100 Destroy() command 574
final animator layout 580, 581
scale or snapping 48 IEnumerator 578, 578, 579, 579
scale tool 11, 13, 14, 15, 79 playing sound 575, 575
screen space 672–674, 672, 673 rebuilding 579, 580
scriptable rendering pipelines 135 self-destroy 574, 574
sculpting software 93 setting TinyExplosion 574
sculpting tool 268, 281, 282 setting up boolean 576, 577
seam artifact 66 transition settings 579, 580, 580, 581
security camera, UV 66, 68, 69, 70, 70 turning off 576, 576
security cameras 533 smart material 102–103
modelling 7–29, 7–32, 31 smoothness remapping 181
Separate command 33–34 snapping 172–173
setting up animator Snapping 41
assigning animator controller “Snap to Projected Center” 379, 379
EllenEnemyController 456, 458 Soften Edge command 10, 11, 13, 14, 253
assigning EllenEnemyAvatar as Source sourceimages folder 94
avatar 455, 455 spacing 431
exporting animation 463, 463 spot light 214, 214–215, 220, 221, 222, 223,
gun in hand 461, 462 224, 227
importing animation into animator 458, 459 Standard Assets 199, 200
import settings for pistol animations status bar, Substance Painter UI 96
454–455, 455 Steel Gun Painted 124–125, 126
import settings for rig 454, 454 Steel Painted Scraped Dirty 103, 104, 105,
inherit avatar from EllenEnemy 456, 457 112, 113
making Ellen_Gun, child of right hand joint straight lines drawing method 106
460–461, 461 straps layer 122–123, 123, 124
positioning 460, 460 stretching, UV mapping 316
preparing pistol idle, renaming and style sheet 244
looping 456, 458 Subdivision Axis 27
743
Substance Painter 92, 93, 118, 322, 356, 363 topology 6, 7, 260, 263, 282
UI 96, 96–97 error 302
substance painter output 450, 450, trail renderer
508–510, 509 adjusting width and length 584, 585
sweater, character modeling 284, 285, 285, 286 BulletReload IEnumerator 589, 590
symmetry 12, 12 construction 587, 588
syntax 469 creating, naming and sizing GunBullet
582, 583
Target Weld Tool 28 creating and setting up material 586, 586
tessellated NURBS 35, 36 creating GunLaunchPoint 582, 583
Tessellation section 35, 43 creating variables 586, 587
texel density 71–73, 80 deducting 1 from ammoCount 588, 589
for other models 81–86 destroy 588, 588
UV mapping 316 dragging 584, 585
Texture Set List 97 ensuring 592, 592
texturing 91–92, 132 filling variables 586, 587
Ambient Occlusion 98 hack-n-slash games 584
baking 93 new boolean parameter 591, 591
generators 100, 101–122, 102, 104–107, providing way out 593, 593
109–121 setting up transitions 590, 591
levels 122–129, 123–129 temporarily turning off 588, 588
light direction 97–98 turning on canFireBullet boolean 587, 587
modular pieces 94 waiting for 12 frames 588, 589
export models 94, 95 transform, Maya model 22–24
import to Substance Painter 96–97 translation 3–4
models arrangement 94, 95 tri-planar projection 323
navigation 97 tube model 37
PBR 92–93 tweaked topology 269, 270
material channels 98–100, 100, 101 2D viewport, navigation 97
with photoshop 316 256 × 256 floor piece 57, 58
rest of models 129, 130, 131, 131 two-handed weapon setup 424–427, 426
result of 129, 130–131
in Substance Painter 316 UI elements
Substance Painter UI 96, 96–97 case switches/switch statements 688–693,
texturing software 61 689–693
3D Cut and Sew UV Tool 303 creating variables 686–687, 687
arms and hands cutting 305 filled in variables 687, 688
ear cutting 303 health 693–695, 695
eyeball UV mapping 308 interactivity 696
hair 309 UI panel 97
sweater cutting 315 uneven UV distribution 310
3D model 3 Unity asset creation
3D viewport, navigation 97 bit about Unity UI 140–143
3D Cut and Sew UV tool 67 colliders 156–159, 157
thumb and tip topology 274, 274, 275 creating empty HDRP project 139, 139
Time Slider 422, 427, 428, 428 creating prefabs 155–159, 156
timing 431 efficient layout 140, 140
toggle symmetry 105, 106 exporting asset from Maya and substance
Toolbox 24 painter 144–155
tools bar, Substance Painter UI 96 game engines 133–134
744
levels of power 134 screen space 672–674, 672, 673
material adjustment 159–169 title in place 699, 700
modules installation 137, 138 tying up loose ends 705–707, 706–707
optimizing layout 140, 140 visual effect 697
rebuilding materials 150–154, 152–154 UV
rendering pipelines 135 the floor 63–71, 63–71
Unity Hub 136–137, 138 for other models 81–89
Unity asset store 726 pod model 74–89, 75–89
Unity-centric approach 466 UV Editor 57, 58, 58, 59
Unity Hub 136–137, 138 UV mapping 57, 297, 299–300, 319–320
Unity level creation body UV 302–308, 303–308
exit Prefab editor 205, 205 character UV mapping 300
importing package 200, 201 mesh inspection and cleanup 300–302,
layout 171–198 301, 302
long view 173 cutting process
organizing and prefab-manipulation hide the seams 316
techniques 172 stretching 316
placed FPSController 200, 205 texel density 316
play button 204, 205 eye UV 308–309, 309
post script 206–207 garment UV 312–319, 313–315, 317–319
settings for point light 203–204, 203 hair UV 309–311, 310–312
snapping 172–173 materials arrangement 318, 319, 319
walking through 199–205 UV points 59–60, 60
Unity UI UV random color 123
game 141 UV shell 64, 75, 76
hierarchy 142 UV tiles 60–61, 60, 61
inspector 142
organized Unity project 143, 143 variables, C#
project 142 Audio Source component 496, 496
scene 141 Audio Source settings 495, 495
streamlined project 143, 143 declaration 489, 490
universal render pipeline (URP) 135 DOLocalMoveX function 491–492, 492
unparenting 32 hold Audio Source 496, 496
upper body, character texturing 340–344, information buckets 489
341–348 instances 494, 494
upper shell hole 19, 19 moving the doors to open position
user interface (UI) 490, 491
buttons and moving between scenes playing doorSound 497, 497
696–707 populating script 493, 493
changed UI text 698, 698 private 489
defined 671 public 489, 490, 490
duplicated button 699, 700 tweak and update 493
elements effect 686–696 using DOTween 491, 492
imported image 697, 697 Vertex 4
interactive buttons 701–705, 702–704 vertex snap method 161, 162
Maya modeling 2, 2 video cards 210
moving StartButton 699, 700 View Control 41
providing instructions 701, 701 viewport, Substance Painter UI 96
rect tool 699, 699 Viewport 2.0. 2
reticle, ammo and health 674–685 virtual environments 159
745
visual appearance 244 walk animation 433–434, 435
visual studio wall models 118
adding script 484, 485 watch
applied SlidingDoorScript 484, 485 character modeling 290, 292
built-in function's 483, 483 character texturing 361, 362, 363
code creation and editing 472, 472 watchband, character modeling 292, 293
coding, trigger 483, 484 weapons
color scheme 474 character modeling 292–294, 293, 294
format the function 483, 484 firing gun and ammo 582–593
IDE 470 grenade launcher 562–582
installation 470 movement 422–424, 423, 425
interface 471, 471 raycasting 593–600
libraries 471, 471 workflow, character modeling 245
opening doors 478–485
simple message coding 474, 475 ZBrush 61, 93, 245, 251, 282, 297
volumetric lighting artifacts 185 zero length edge 43
746