GDKB

Coordinate Systems

Beginner20 Minutes readUpdated July 21, 20263 related concepts

A coordinate system is a fixed reference frame — an origin point plus a set of directional axes — that turns "where something is" into numbers. Every position, rotation, and movement in a game is expressed relative to some coordinate system, and knowing *which* one a given number is relative to is just as important as the number itself. A position of `(5, 0, 0)` means nothing on its own; it means "5 units along the X axis from this particular origin."

On this page

Coordinate Systems

Summary

A coordinate system is a fixed reference frame — an origin point plus a set of directional axes — that turns "where something is" into numbers. Every position, rotation, and movement in a game is expressed relative to some coordinate system, and knowing which one a given number is relative to is just as important as the number itself. A position of (5, 0, 0) means nothing on its own; it means "5 units along the X axis from this particular origin."

Why This Matters

Without a shared, well-understood coordinate system, numbers describing position are meaningless in isolation — (10, 2, -3) could be far away or right next to the camera depending on what it's measured relative to. Bugs where an object "teleports" to the wrong place, or moves in the wrong direction after being parented to something else, are almost always a coordinate system mismatch: code assumed one reference frame (world space) while the actual number was expressed in another (local space relative to a parent). Understanding coordinate systems explicitly is what lets you diagnose and avoid this entire category of bug.

Mental Model

A coordinate system is a map's "you are here" marker plus its compass rose, not the terrain itself. The same physical location can be described completely differently depending on which map you're using and where that map's origin is — "3 blocks north of the fountain" and "40 meters east of the train station" might describe the identical spot. Neither description is wrong; they're just relative to different reference frames. A game object's position works the same way: the same physical point in the world has different numeric coordinates depending on whether you're measuring from the world's origin or from a parent object's origin.

Core Explanation

  • An origin point and a set of axes define the system. Typically three perpendicular axes (X, Y, Z) meeting at a zero point — every position is expressed as "how far along each axis from that zero point."
  • World space is measured from the scene's fixed, global origin. A world-space position is absolute — the same physical point always has the same world-space coordinates, regardless of what else is in the scene.
  • Local space is measured relative to a parent object's own origin. A child object's local position describes its offset from its parent, not from the world — moving the parent moves every child's effective world position without their local coordinates changing at all (see [[CON-0051]]).
  • Left-handed and right-handed systems, and axis "up" conventions, differ between engines. Unity uses a left-handed system with Y-up; Unreal uses a left-handed system with Z-up — the same real-world direction can be represented by different axis values depending on which engine's convention is in use, which matters when porting math or assets between them.

Syntax / Theory

Engine-neutral (concept)

text
World space:  position measured from the world's fixed origin (0, 0, 0)
Local space:  position measured from a parent's origin, moves with the parent

C# (Unity — Y-up, left-handed)

csharp
transform.position;       // World-space position.
transform.localPosition;  // Position relative to the parent (or world, if no parent).
csharp
// A child weapon's local position stays constant relative to the hand,
// even though its world position changes every time the hand moves.
weaponTransform.localPosition = new Vector3(0.1f, 0f, 0.3f);

C++ (Unreal — Z-up, left-handed)

cpp
GetActorLocation();          // World-space location.
GetActorRelativeLocation();  // Location relative to its attach parent.

Both engines expose the identical world-vs-local distinction, just with different axis conventions (Unity: Y is up; Unreal: Z is up) — a raw vector copied directly between the two without adjustment will not point in the same visual direction.

Practical Example

A UI element attached to a character's head needs to follow the character regardless of where the character currently is in the world.

csharp
public class HealthBarFollower : MonoBehaviour
{
    [SerializeField] private Transform headBone; // Parent — defines local space.

    void Start()
    {
        transform.SetParent(headBone);
        transform.localPosition = new Vector3(0f, 0.2f, 0f); // Always "slightly above the head."
    }
}

Because localPosition is relative to headBone, the health bar stays correctly positioned above the head no matter where the character walks in world space — the local offset never needs to be recalculated.

Common Mistakes

  • Mixing world-space and local-space values without converting between them. Setting a child's localPosition when a world-space target position was actually intended (or vice versa) places the object at the wrong location — the two are only identical when there's no parent.
  • Assuming "up" is the same axis across engines. Code or math ported from a Y-up engine to a Z-up one (or vice versa) without adjusting which axis represents "up" produces objects that are rotated or positioned incorrectly.
  • Forgetting that parenting changes an object's effective world position immediately. Attaching an object to a moving parent without accounting for the parent's current transform can cause a visible "jump," since the child's world position is now the combination of the parent's transform and the child's local offset.
  • Hardcoding world-space positions for something that should be relative. A UI marker meant to always appear "in front of the player" needs to be expressed relative to the player's transform, not as a fixed world coordinate that becomes wrong the moment the player moves.

Game Development Example

A camera rig follows the player using an offset expressed in the player's local space, so the camera's relative position stays correct regardless of which direction the player is facing.

csharp
public class CameraRig : MonoBehaviour
{
    [SerializeField] private Transform player;
    [SerializeField] private Vector3 localOffset = new Vector3(0, 5, -8);

    void LateUpdate()
    {
        transform.position = player.position + player.rotation * localOffset;
    }
}

Multiplying the offset by player.rotation converts it from "relative to the player's facing direction" into a world-space offset — without this conversion, the camera would stay behind the player only while the player faced one specific fixed world direction.

Best Practices

  • Be explicit, in variable names and comments, about which coordinate space a given position or vector is expressed in.
  • Convert deliberately between world and local space rather than assuming they're interchangeable — most engines provide built-in conversion methods/properties for this.
  • Account for each engine's specific axis convention (which axis is "up," handedness) when porting math or assets between engines.
  • Prefer expressing UI/attachment offsets in local space so they remain correct as the parent moves, rather than recalculating a world-space position every frame.

Exercises

  1. Parent a small object to a moving platform, set its localPosition to a fixed offset, and observe how its world position changes as the platform moves while its local position stays constant.
  2. Take the CameraRig example and remove the player.rotation * multiplication, then describe what happens to the camera's position when the player turns to face a different direction.
  3. You're building a multiplayer game where a weapon attachment point needs to be shared between a first-person view model and a third-person character model with different bone hierarchies. Decide whether to store the attachment offset in world space or local space, and justify the trade-off.
  4. Research the difference between a left-handed and right-handed coordinate system, and explain, in your own words, what visually changes about a rotation's direction when switching between them.
  • Vectors — a coordinate system is the reference frame that gives a vector's individual numbers their actual spatial meaning.
  • Transform Hierarchies — the parent-child relationship that produces the distinction between local and world space in the first place.
  • Direction Vectors — direction, like position, is always expressed relative to some coordinate system, most commonly either world space or an object's own local facing.

Further Reading

Related Concepts