CFrame constructors
Identity constant and rotation constructors from an axis, a basis or Euler angles.
Syntax
CFrame.identity -> CFrame
CFrame.fromAxisAngle(axis: Vector3, angle: number) -> CFrame
CFrame.fromMatrix(position: Vector3, vX: Vector3, vY: Vector3, vZ?: Vector3) -> CFrame
CFrame.fromEulerAnglesXYZ(rx: number, ry: number, rz: number) -> CFrame
CFrame.fromEulerAnglesYXZ(rx: number, ry: number, rz: number) -> CFrame
Parameters
| Parameter | Type | Description |
|---|---|---|
axis | Vector3 | Rotation axis; normalized internally, must not be zero-length. |
angle | number | Rotation in radians. |
position | Vector3 | Translation of the resulting CFrame. |
vX vY vZ | Vector3 | Basis columns. vZ defaults to vX × vY. |
rx ry rz | number | Euler angles in radians. |
Returns
| Type | Description |
|---|---|
CFrame | The constructed CFrame. |
Description
CFrame.identity is a ready-made zero-rotation CFrame at the origin.
fromEulerAnglesXYZ is the same function as CFrame.Angles, applied in X, Y, Z order; fromEulerAnglesYXZ applies Y first, then X, then Z.
fromMatrix orthonormalizes the supplied columns, so slightly non-orthogonal input is accepted; a degenerate basis raises an error.
Example
local cf = CFrame.fromAxisAngle(Vector3.new(0, 1, 0), math.rad(90))
print(cf.LookVector.X) -- -1
local m = CFrame.fromMatrix(Vector3.new(0, 5, 0), Vector3.new(1, 0, 0), Vector3.new(0, 1, 0))
print(m.Position)
Notes
CFrame.identity— A shared constant value; treat it as read-only.fromAxisAngle zero axis— Raises "axis is zero-length".