Skip to content
Tutorials Center
My learning

Topics

Lesson 7 of 36 ยท Editor and Project Basics

Transforms and Coordinate Systems

Master the Unity Transform: left-handed axes, position, rotation with Euler angles and quaternions, scale, parenting, local versus world space, and the vector math behind it, with runnable stand-ins.

The Transform is the one component every GameObject has, and the one you touch most. It stores where an object is (position), how it is turned (rotation), how big it is (scale), and which object is its parent. Almost every script you write reads or changes a transform, so the concepts in this lesson, especially the difference between local and world space, are worth getting right now.

You will also meet vectors: a Vector3 is three numbers (x, y, z) used for positions, directions and velocities. The runnable stand-ins implement a small Vec3 in plain C# so you can try the same math Unity performs.

The coordinate system

Unity uses a left-handed, Y-up system:

  • X points right,
  • Y points up,
  • Z points forward (into the screen in the default view).

One unit is, by convention, one meter. Physics, lighting and audio assume this, so a character should be around 1.8 units tall and a door around 2.

For 2D games Unity still uses 3D coordinates; the camera simply looks along the Z axis and objects usually sit at z = 0.

Position, rotation and scale

C#
// read-only Unity script
using UnityEngine;

public class TransformDemo : MonoBehaviour
{
    void Start()
    {
        transform.position = new Vector3(2f, 0f, 5f);          // world position
        transform.rotation = Quaternion.Euler(0f, 90f, 0f);    // turn 90 degrees around Y
        transform.localScale = new Vector3(1f, 2f, 1f);        // twice as tall
        Debug.Log(transform.forward);   // direction the object faces, world space
    }
}
  • Position is a Vector3. You cannot change one axis directly (transform.position.x = 3 is a compile error because Vector3 is a struct copy). Assign a whole vector: var p = transform.position; p.x = 3; transform.position = p;.
  • Rotation is stored as a quaternion, four numbers that avoid the problems of angles (more below). The Inspector shows friendlier Euler angles: rotations in degrees around X, Y and Z, applied in the order Z, X, Y.
  • Scale multiplies the object's size on each axis. Negative scale mirrors the object.

The direction properties transform.forward, transform.right and transform.up give the object's own axes in world space. Moving "forward" for a character is transform.position += transform.forward * speed * Time.deltaTime.

Local space versus world space

Each transform has two sets of numbers:

Property Meaning
position, rotation, lossyScale World space: relative to the scene origin
localPosition, localRotation, localScale Local space: relative to the parent

An object without a parent has identical local and world values. For a child, the Inspector shows the local values. If a Wheel is a child of Car with localPosition = (1, 0, 1.5), the wheel is always 1.5 units in front of the car's center and 1 unit to its right, in the car's own orientation: when the car turns, the wheel turns with it, and its world position changes though its local position does not.

Use local space for things that belong to a parent (a weapon in a hand, a UI icon in a panel) and world space for absolute targets ("go to the marker").

C#
// read-only Unity script
Vector3 worldPoint = transform.TransformPoint(new Vector3(0, 0, 2)); // 2 units ahead of me, as a world point
Vector3 localPoint = transform.InverseTransformPoint(worldPoint);    // back to my local space

Local to world: the math in a stand-in

A child's world position is the parent's position plus the child's local position rotated and scaled by the parent. This stand-in handles the rotation around Y only, which is the most common case in games, and shows the difference between local and world.

C# Local to world position (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

With yaw = 0 the wheel is at (11, 0, 1.5). After the car turns 90 degrees the wheel's world position moves around the car, but its local position is still (1, 0, 1.5). This is exactly what TransformPoint does in Unity (with full 3D rotation).

Vectors you use every day

Vector3 supports the operations you need for movement and aiming:

  • Addition/subtraction: target - position is the vector from you to the target.
  • Magnitude: v.magnitude is its length; Vector3.Distance(a, b) is the distance between two points.
  • Normalization: v.normalized keeps the direction but sets the length to 1. Use it for direction-only values.
  • Dot product: Vector3.Dot(a, b): for unit vectors it is the cosine of the angle between them; positive means "roughly the same direction". Handy for "is the enemy in front of me?".
  • Cross product: Vector3.Cross(a, b) gives a vector perpendicular to both.
  • Lerp: Vector3.Lerp(a, b, t) blends between two points; t = 0.5 is the midpoint.
C# Distance, direction and the dot product (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

A dot product above zero means the target is somewhere in front; close to 1 means almost straight ahead. Field-of-view checks use a threshold such as dot > 0.5 (a 120-degree cone).

Euler angles and quaternions

Euler angles are easy to read but have a flaw called gimbal lock, where two axes line up and a rotation is lost. They also cannot be blended smoothly across 360 degrees. So Unity stores rotation as a quaternion and you work with helper functions rather than raw numbers:

  • Quaternion.Euler(x, y, z) builds a rotation from angles.
  • Quaternion.LookRotation(direction) points the forward axis at a direction.
  • Quaternion.Slerp(a, b, t) turns smoothly from one rotation to another.
  • q1 * q2 combines rotations; q * vector rotates a vector.
  • transform.Rotate(x, y, z) adds a rotation; transform.LookAt(target) faces a target.

Never edit rotation.x or .w directly, and avoid reading eulerAngles to add to it yourself (values wrap at 360 degrees).

Parenting from code

C#
// read-only Unity script
child.SetParent(parent);              // keeps the child's world position (worldPositionStays = true)
child.SetParent(parent, false);       // keeps its local values instead
child.SetParent(null);                // detach to the scene root
Debug.Log(parent.childCount);
Transform first = parent.GetChild(0);

Moving a child with transform.position (world) is different from localPosition. If a script on a child "does nothing", check which space it writes to.

Common mistakes

  • Changing position.x directly (compile error) instead of assigning a new Vector3.
  • Mixing position and localPosition on child objects.
  • Non-uniform scale on parents with rotated children, which skews them.
  • Using eulerAngles for smooth turning; use Quaternion.Slerp or RotateTowards.
  • Forgetting that 1 unit is 1 meter, then making physics feel floaty because objects are 100 units big.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which axis points up in Unity?

    Unity is Y-up: X is right, Y is up, Z is forward.
  2. 2. What does localPosition describe?

    localPosition is measured in the parent's space. For objects with no parent it equals position.
  3. 3. Why does Unity store rotations as quaternions?

    Quaternions avoid gimbal lock and blend smoothly, though Euler angles are shown in the Inspector for convenience.
  4. 4. Vector3.Dot(facing, directionToTarget) with both unit vectors returns 0.9. What does this mean?

    For unit vectors the dot product is the cosine of the angle; 0.9 means about 26 degrees.

Summary

  • The Transform stores position, rotation, scale and parent; Unity is left-handed and Y-up, with one unit equal to one meter.
  • World properties are absolute; local properties are relative to the parent.
  • Assign whole vectors; use quaternion helpers rather than editing components.
  • Distance, normalized, Dot and Lerp cover most gameplay vector math.
  • TransformPoint and InverseTransformPoint convert between spaces.

Next: Prefabs, Assets and Scenes