CodeBlanks Logo Icon CodeBlanks

Local vs world space

Learn the difference between local and world space.

Local and World Space

In Unity, World Space describes an object's position relative to the scene's global coordinate system. Local Space describes its position and rotation relative to its own parent. If an object has a parent, its local coordinates depend on that parent's coordinate system.

World Position: (10, 0, 0)
Local Position: (2, 0, 0)

These two values can differ for the same object because they represent different coordinate systems.

Parent and Child Objects

In Unity, one Transform can be a child of another Transform. A child object's localPosition is calculated relative to its parent, while position represents its world coordinates. When the parent moves, the child's world position can also be affected.

Parent
  Position: (5, 0, 0)
  └── Child
      Local Position: (2, 0, 0)
      World Position: (7, 0, 0)

This hierarchy allows objects to be organized in a connected structure.

Practice Print Local and World Positions

Create a Start method in a Unity C# class. Print the object's world position first, followed by its local position relative to its parent, using Debug.Log. Use transform.position and transform.localPosition in that order.

Starter code

Player.cs
using UnityEngine;

public class SpaceInfo : MonoBehaviour
{
    void Start()
    {
        // Print world and local positions.
    }
}

Sample solution

Player.cs
using UnityEngine;

public class SpaceInfo : MonoBehaviour
{
    void Start()
    {
        Debug.Log(transform.position);
        Debug.Log(transform.localPosition);
    }
}

Expected output

(7.00, 0.00, 0.00)
(2.00, 0.00, 0.00)

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which property represents an object's position relative to its parent?

  • transform.rotation
  • transform.localScale
  • transform.position
  • transform.localPosition Correct answer

Explanation: localPosition specifies the object's position relative to its parent's coordinate system rather than world coordinates.

2 Read the Local Position

Question
Vector3 relativePoint = transform.____;
Answer
Vector3 relativePoint = transform.localPosition;

Explanation: localPosition returns the object's position relative to its parent as a Vector3.

3 Coordinate Systems

Term Meaning
World Space The scene's global coordinate system
Local Space Coordinate system relative to parent
position Returns the world position
localPosition Returns position relative to parent

All lessons in Beginner