Skip to content

Rotation

Global · Rotation · server and client scripts

Rotation is an immutable unit-quaternion 3D orientation. Read Forward, Up, and Right basis vectors, rotate a vector with :Apply, compose two rotations with *, interpolate with :Lerp, invert with :Inverse, or convert with :ToEuler, :ToAxisAngle, and :AngleTo.

Example

-- Server script: rotate a part 90 degrees around the Y axis.
local part = World.Spawn({ Position = Vector3.Zero, Rotation = Rotation.Identity, Shape = "Box" })
part.Rotation = Rotation.fromAxisAngle(Vector3.YAxis, 90)

fromEuler

Function
fromEuler(degrees: vector) -> Rotation

Rotation.fromEuler creates a rotation from YXZ Euler angles in degrees.

Example

-- Server script: build a rotation from Euler angles in degrees.
local r = Rotation.fromEuler(Vector3.new(15, 45, 0))
print(r:ToEuler())

fromAxisAngle

Function
fromAxisAngle(axis: vector, degrees: number) -> Rotation

Rotation.fromAxisAngle creates a rotation around axis by degrees. A zero axis returns Rotation.Identity.

Example

-- Server script: rotate a forward vector around +Y.
local turn = Rotation.fromAxisAngle(Vector3.YAxis, 90)
local facing = turn:Apply(Vector3.new(0, 0, -1))
print(facing)

lookAt

Function
lookAt(forward: vector, up: vector?) -> Rotation

Rotation.lookAt creates a rotation whose Forward points along forward, using up (defaults to Vector3.YAxis) as the reference up direction.

Example

-- Server script: orient a turret toward a target direction.
local aim = Rotation.lookAt(Vector3.new(0, 0, -1))
print(aim.Forward)

Identity

PropertyRead only
Identity: Rotation

Rotation.Identity is the zero rotation whose Forward is (0, 0, -1), Up is (0, 1, 0), and Right is (1, 0, 0).

Default Rotation.Identity