In DCC (digital content creation) applications—such as 3ds Max, Maya, or Blender—a primitive object is, by definition, an object that can be defined by a set of parameters. Some examples of primitives are sphere, cube, capsule, and cylinder. A sphere is defined by a radius and the number
of longitudinal and latitudinal segments it has. A box or cube is defined by height, width, length, and its number of segments. When an object cannot be described by a set of parameters, it is called a “mesh.” A mesh is a collection of vertices, edges, and faces that are used to build the object in 3D space. A primitive is a mesh, but a mesh (no parametric way to define or describe it) is not a primitive. In Unity, you have less control over the parameters, but the included 3D gameObjects are primitives, nonetheless. These primitives can be used as is or as the base for more complex gameObjects.
Let’s start by using the project created in the last section of Chapter 1, the UnityTest project.
1. If Unity is not already open to the UnityTest project, click the Unity icon on your desktop.
2. In the Project Wizard, select the UnityTest project.
While the scene is small and you are not adding game play, it will be useful to use the default layout.
3. Click the Layout button at the top right of the editor to open the list of presets.
4. Select Default.
The layout reverts to having the Hierarchy view on the left, the Inspector on the right, the Scene and Game views tabbed in the center, and the Project view underneath.
The project has a default, nameless scene, but it has not yet been saved.
5. From the File menu, select “Save Scene as.”
6. Save the scene as Primitives.
The new scene asset appears in the Project view, sporting the Unity application icon (Figure 2-1).
Figure 2-1. The new Unity scene asset in the Project view
7. From the GameObject menu, Create Other, select Cube (Figure 2-2).
A cube is created in the center of the viewport.
Transforms
All gameObjects have a Transform component. It keeps track of where the object is in space, what its orientation is, and if it has been scaled. Unlike the viewport X, Y, and Z global coordinates, gameObjects can be moved, rotated, or scaled at will. You can transform them in edit mode, and they can be animated during runtime.
If you have not navigated through the scene view since the project was created, the cube should have been created at 0, 0, 0. Unlike many Autodesk products where Z is up in the world, in Unity, Y is the upward direction. You should see your cube with its transform gizmo, specifically the Position gizmo, clearly visible. The arrows follow the convention of RGB = XYZ, or the red arrow is the X direction, the green arrow is the Y direction, and the blue arrow is the Z direction. Z is the direction Unity considers as forward.
Figure 2-2. Creating a cube
1. With the cube selected, look at the Transform component at the top of the Inspector (Figure 2-3).
Figure 2-3. The cube’s Transform component
2. If the X, Y, and Z positions are not all 0, you can type it in to move the cube to that location.
While you are in the Inspector, take a look at the cube’s Scale. It defaults to 1 x 1 x 1. Unity considers 1 unit to equal 1 meter, approximately 3 feet.
You don’t need to type values directly into the number fields, because many of Unity’s entry box labels act as sliders.
3. Position your cursor over the Rotation’s Y label.
4. Click and drag it left and right to rotate the cube in the Scene view.
5. Leave the cube at about -60 degrees.
6. At the top of the editor, make sure the coordinate system is set to Local (it is a toggle), not Global, and that the Transform is set to Move (Figure 2-4).
7. Click on the Z arrow in the viewport, and drag the cube while watching the Position values in the Inspector.
The cube is moving in its local Z direction, but its X position is updated as well.
8. Change the coordinate system to Global, and pull the cube in the Global Z direction.
This time, the only value being updated in the Inspector is the Z Position. When you transform an object, its location and orientation are kept in world coordinates.
You can also rotate and scale objects using the transform modes at the top left. Just like position, rotate can use local or global coordinates.
1. Click to active Rotate mode (Figure 2-5).
Figure 2-4. The coordinate system set to Local, Move transform active
2. Rotate the cube by placing the cursor over the circular parts of the gizmo and dragging.
3. Change the mode to Scale (Figure 2-6).
Figure 2-6. Scale mode and the Scale gizmo Figure 2-5. Rotate mode and the Rotate gizmo
Unlike position and rotation, Scale mode allows you to scale an object only on its local coordinate system. This prevents objects that have been rotated from getting skewed.
4. Scale the cube on any of its axes.
5. In the Inspector, set all of its Scale values back to 1.
6. Set the mode back to Move in the upper left corner of the editor.
7. Set the coordinate system to Local.
So far, you have dealt with only a single object. With multiple objects, there are some tools that will help you with positioning.
1. Hold the middle mouse button down, and pan the Scene view so that the cube is off to the left, but not out of the viewing frustum (the boundaries of the viewport window).
2. From the GameObject menu, Create Other, select Sphere.
3. The Sphere is created in the center of the viewport, not at 0, 0, 0 (Figure 2-7).
Figure 2-7. The new created Sphere, not located at 0, 0, 0
To move the sphere to the same location as the cube, you could copy and paste the values from the cube to the sphere, but that would be tedious. Instead, you will be using a typical Unity workflow where the target object is focused or framed in the viewport, then the object to move is moved to that location. Note that it will not affect the object’s orientation.
4. Select the Cube in the Hierarchy view.
5. Double-click the cube in the Hierarchy view, or move the cursor to the Scene view and press the F key.
The Scene view zooms in to the selected object. Unity calls this action “frame selected.”
6. Now select the sphere by clicking on it in either the Hierarchy view or the Scene view.
7. From the GameObject menu, select “Move to View.”
The sphere is moved to the center of the viewport as defined by the cube’s location (Figure 2-8).
Figure 2-8. The scene focused to the cube, and the sphere moved to the scene’s focus 8. Select the cube, and check the Inspector for its Rotation values.
It should still have -60 (or whatever you left it at) as its Y Rotation value.
9. Select the Sphere, and check its Rotation values.
The sphere was moved to the cube with “Move to View,” but its rotation was not changed.