codeAPI Reference

Sandbox.Transform - Position, Rotation and Scale

calendar_today May 3, 2026 schedule ~1 min read person patrickjr verified 50

Sandbox.Transform

Position, rotation, and scale combined.

Overview

Transform combines position, rotation, and scale into a single matrix for efficient calculations.

Access

CSHARP
// From GameObject
Transform tx = GameObject.Transform;

// Or shortcut
Transform tx = Transform;

Components

PropertyTypeDescription
PositionVector3World position
RotationRotationWorld rotation
ScaleVector3Scale

Matrix

CSHARP
// Get transform matrix
Matrix matrix = tx.Matrix;

// Transform point
Vector3 world = tx.PointToWorld(local);
Vector3 local = tx.PointToLocal(world);

// Transform direction
Vector3 worldDir = tx.DirectionToWorld(localDir);

Local Space

CSHARP
// Local to world
Vector3 world = tx.PointToWorld(new Vector3(10, 0, 0));

// World to local
Vector3 local = tx.PointToLocal(worldPos);

Changing Transform

CSHARP
// Move
tx.Position += Vector3.Forward * 100f;

// Rotate
tx.Rotation *= Rotation.FromYaw(45f);

// Scale
tx.Scale = new Vector3(2, 2, 2);

World vs Local

CSHARP
// World transform (absolute)
WorldPosition = new Vector3(100, 0, 50);
WorldRotation = Rotation.LookAt(target);

// Local transform (relative to parent)
LocalPosition = new Vector3(0, 20, 0);
LocalRotation = Rotation.FromYaw(90f);

Common Uses

CSHARP
// Get forward direction
Vector3 forward = tx.Rotation.Forward;

// Distance to
float dist = (target.WorldPosition - WorldPosition).Length;
Was this helpful?