codeAPI Reference

Sandbox.Rotation

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

Sandbox.Rotation

Represents 3D orientation.

Overview

Rotation stores an orientation in 3D space, handling quaternion math internally.

Creation

CSHARP
// From angles
Rotation rot = Rotation.FromYawPitchRoll(yaw, pitch, 0);

// Look at direction
Rotation rot = Rotation.LookAt(Vector3.Forward);
Rotation rot = Rotation.LookAt(target - position);

// From axis
Rotation rot = Rotation.FromAxis(Vector3.Up, 90f);

Constants

ConstantDescription
Rotation.IdentityNo rotation
Rotation.LookAt(Vector3)Face direction

Applying to Vectors

CSHARP
Rotation rot = WorldRotation;

// Get direction vectors
Vector3 forward = rot.Forward;
Vector3 right = rot.Right;
Vector3 up = rot.Up;

// Rotate a vector
Vector3 rotated = rot * Vector3.Forward;

Operations

CSHARP
// Combine rotations
Rotation combined = rot1 * rot2;

// Inverse
Rotation inverse = rot.Inverse;

// Lerp
Rotation smooth = Rotation.Slerp(from, to, 0.5f);

Angles Conversion

CSHARP
// To/from Angles
Angles angles = rot.Angles();
Rotation rot = angles.ToRotation();

// Extract components
float yaw = rot.Yaw();
float pitch = rot.Pitch();

Smoothing

CSHARP
// Smooth rotation change
Rotation target = LookAt(targetPos);
WorldRotation = Rotation.Slerp(WorldRotation, target, Time.Delta * 5f);

Local vs World

CSHARP
// Local rotation (relative to parent)
LocalRotation = Rotation.FromYaw(45f);

// World rotation (absolute)
WorldRotation = Rotation.LookAt(target - WorldPosition);

From ToRotation

CSHARP
// Shortest rotation between two directions
Rotation turn = Rotation.FromToRotation(fromDir, toDir);
Was this helpful?