In this lesson, you will learn how to navigate and place objects within Unity’s 3D environment using the Cartesian coordinate system.
Understanding the Axes
In Unity, every object’s position is defined by three numbers, represented as a Vector3 (X, Y, and Z). To visualize this, think of the center of your Scene view as the origin point (0, 0, 0).
- The X-axis (Red): This represents horizontal movement. Moving along this axis shifts your object left or right.
- The Y-axis (Green): This represents vertical movement. Moving along this axis shifts your object up or down (think of "Y for Yonder/Up").
- The Z-axis (Blue): This represents depth. Moving along this axis shifts your object forward or backward within the scene.
Mapping Positions
When you select a GameObject in the Hierarchy, the Inspector displays these values under the Transform component. If you set a position to (1, 2, 5), you are telling Unity to place that object 1 unit to the right, 2 units up, and 5 units forward from the absolute center of the world.
You can manipulate these coordinates directly in your scripts to control object placement. For example:
void Start()
{
// Sets the object's position to 1 unit right, 2 units up, and 5 units forward
transform.position = new Vector3(1f, 2f, 5f);
}
Visualizing the Grid
While the Inspector handles the numbers, the Scene view is your best tool for spatial awareness. Look at the "Scene Gizmo" in the top-right corner of the Scene view. The red, green, and blue arrows correspond exactly to the X, Y, and Z axes. By clicking and dragging these arrows, you are physically updating the Cartesian coordinates of your object in real-time.
As you build more complex scenes, remember that these coordinates are always relative to the "World" (global space) unless the object is a child of another parent object, in which case it uses local coordinates. Keeping these three axes clear in your mind is the first step toward mastering level design.
Key Takeaway: Unity uses the X, Y, and Z axes to define an object’s location in 3D space, where X is horizontal, Y is vertical, and Z provides depth.