CFrame methods
Component access, inversion, interpolation, space conversion and translation operators.
Syntax
cf:GetComponents() -> number x12
cf:Inverse() -> CFrame
cf:Lerp(goal: CFrame, alpha: number) -> CFrame
cf:ToWorldSpace(value: CFrame | Vector3) -> CFrame | Vector3
cf:ToObjectSpace(value: CFrame | Vector3) -> CFrame | Vector3
cf + Vector3 -> CFrame
cf - Vector3 -> CFrame
cf.Rotation -> CFrame
cf.XVector / cf.YVector / cf.ZVector -> Vector3
cf:ToOrientation() -> rx, ry, rz
cf:ToAxisAngle() -> Vector3, number
Parameters
| Parameter | Type | Description |
|---|---|---|
goal | CFrame | Target orientation and position. |
alpha | number | 0 returns the current CFrame, 1 the goal. |
value | CFrame | Vector3 | A CFrame is composed; a Vector3 is transformed as a point. |
Returns
| Type | Description |
|---|---|
CFrame | Vector3 | number | GetComponents returns 12 numbers, the rest return a new value. |
Description
GetComponents returns X, Y, Z followed by R00, R01, R02, R10, R11, R12, R20, R21, R22.
Inverse transposes the rotation and negates the transformed position.
Lerp interpolates the position linearly and the rotation with quaternion slerp, so the basis stays orthonormal.
ToWorldSpace composes or transforms into world space; ToObjectSpace applies the inverse. The + and - operators translate the position by a Vector3.
Rotation returns a copy with the position zeroed. XVector, YVector and ZVector expose the three matrix columns, with ZVector equal to -LookVector.
ToOrientation is the same decomposition as ToEulerAnglesXYZ. ToAxisAngle returns a unit axis and an angle in the 0..π range; an identity rotation returns axis (1, 0, 0) and angle 0.
Example
local cf = CFrame.new(10, 0, 0)
print(cf:GetComponents())
print(cf:Inverse().Position) -- -10, 0, 0
print((cf + Vector3.new(0, 2, 0)).Position) -- 10, 2, 0
print(cf:ToObjectSpace(Vector3.new(10, 0, 5)))
print(CFrame.Angles(0, math.rad(90), 0):ToAxisAngle())
Notes
ToWorldSpace(CFrame)— Equivalent tocf * other.PointToWorldSpace / PointToObjectSpace— The point-only variants skip the CFrame branch and always return a Vector3.