Skip to Content
Kinemium
Datatypes

CFrame

A position and 3D rotation used for parts, cameras, and spatial math.

CFrame combines a position with a rotation matrix. Every BasePart has one, cameras use one, and most 3D placement math goes through it.

local cf = CFrame.new(0, 5, 0) * CFrame.Angles(0, math.rad(45), 0)
part.CFrame = cf

Constructors

CallResult
CFrame.new()Identity frame at the origin.
CFrame.new(position)Frame at position with no rotation.
CFrame.new(position, lookAt)Frame at position facing lookAt.
CFrame.new(x, y, z)Frame at the given position.
CFrame.new(x, y, z, qx, qy, qz, qw)Frame from a position and quaternion.
CFrame.new(x, y, z, r00, r01, r02, r10, r11, r12, r20, r21, r22)Frame from a position and nine rotation components.

Other constructors:

CallResult
CFrame.Angles(rx, ry, rz)Rotation from three angles in radians.
CFrame.fromEulerAnglesXYZ(rx, ry, rz)Rotation applied in XYZ order.
CFrame.fromEulerAnglesYXZ(rx, ry, rz)Rotation applied in YXZ order.
CFrame.fromOrientation(rx, ry, rz)Rotation from orientation angles.
CFrame.fromAxisAngle(axis, angle)Rotation around axis by angle radians.
CFrame.lookAt(position, target, up?)Frame at position looking at target.
CFrame.lookAlong(position, direction, up?)Frame at position pointing along direction.
CFrame.fromMatrix(position, xVector, yVector, zVector?)Frame from a position and basis vectors. If zVector is omitted, it is the cross product of the other two.
CFrame.identityThe identity frame.

Members

MemberTypeDescription
Position, pVector3World position.
RotationCFrameRotation only, with zero position.
RightVector, XVectorVector3Right direction.
UpVector, YVectorVector3Up direction.
LookVectorVector3Forward direction.
ZVectorVector3Z basis vector.
X, Y, ZnumberPosition components.

Methods

MethodReturnsDescription
Inverse()CFrameInverse transform.
Lerp(goal, alpha)CFrameInterpolates position and rotation.
ToWorldSpace(cf)CFrameApplies cf in world space.
ToObjectSpace(cf)CFrameApplies cf in local space.
PointToWorldSpace(point)Vector3Transforms a point into world space.
PointToObjectSpace(point)Vector3Transforms a point into local space.
VectorToWorldSpace(vector)Vector3Rotates a direction into world space.
VectorToObjectSpace(vector)Vector3Rotates a direction into local space.
Orthonormalize()CFrameRebuilds an orthonormal rotation.
GetComponents(), components()twelve number valuesPosition followed by nine rotation components.
ToEulerAnglesXYZ()three number valuesEuler angles in XYZ order.
ToEulerAnglesYXZ()three number valuesEuler angles in YXZ order.
ToOrientation()three number valuesOrientation angles.
ToAxisAngle()(Vector3, number)Axis and angle in radians.
FuzzyEq(other, epsilon?)booleanComponent-wise comparison. epsilon defaults to 1e-5.
AngleBetween(other)numberAngle between the two rotations, in radians.

Operators

OperatorResult
CFrame + Vector3Frame moved by the vector.
CFrame - Vector3Frame moved by the negated vector.
CFrame * CFrameCombined transform.
CFrame * Vector3Transformed point.
CFrame == CFrameComponent-wise equality.

Order matters for *. a * b applies b first, then a. To move a part relative to its own axes, multiply its CFrame by an offset on the right; to move it in world axes, multiply on the left.

See also

On this page