Roblox Wiki
Advertisement
Roblox Wiki

A CFrame, or Coordinate Frame, is a DataType containing positional and rotational data. It can be used to accurately position BaseParts through their CFrame property, which unlike Position, allows the part to be rotated.

You can position a part just like you would using the Position property.

part.CFrame = CFrame.new(1, 6, 2) -- Places the part at point {1, 6, 2) in the workspace

To create a rotated CFrame at the origin, use:

part.CFrame = CFrame.Angles(math.rad(45), math.rad(90), math.rad(180))

It is worth noting that the rotations are not applied simultaneously, but sequentially. So the previous command rotates in the part's X-axis, then the part's Y-axis, and then the part's Z-axis.

For an explanation of the parameters, see radians.

One interesting fact is that any instance with a property that is a CFrame type, for example, the CFrame property of a BasePart object, is hidden in the properties panel. The "Value" property of a CFrameValue is also hidden, thus needing to be modified from a Script, a Plugin, or through the Command Line.

Constructors

CFrames are one of the many DataTypes available in Roblox Lua. A CFrame can be created by using one of the many constructors. However, note that unlike a BasePart's orientation property, it takes rotational arguments in radians instead of degrees.

Constructor Description

CFrame.new( )

Creates an identity CFrame

CFrame.new( Vector3 v)

Creates CFrame from offset v

CFrame.new( Vector3 v)

Creates CFrame from offset v

CFrame.new( Number x, Number y, Number z)

Creates CFrame from offset (x, y, z)

CFrame.new( Number x, Number y, Number z,
Number qx, Number qy, Number qz, Number qw)

Creates CFrame from offset (x, y, z) and quaternion (qx, qy, qz, qw)

CFrame.new( Number x, Number y, Number z,
Number R00, Number R01, Number R02,
Number R10, Number R11, Number R12,
Number R20, Number R21, Number R22)

Creates CFrame from offset (x, y, z) and rotation matrix (R00, R01, R02, R10, R11, R12, R20, R21, R22)

CFrame.fromEulerAnglesXYZ( Number x, Number y, Number z)

or

CFrame.Angles( Number x, Number y, Number z)

or

CFrame.fromOrientation( Number x, Number y, Number z)

Creates a rotated CFrame at (0,0,0) rotated around the three axes in order (relative to the CFrame). Angles in radians

CFrame.fromEulerAnglesYXZ( Number rx, number ry, Number rz)

Creates a CFrame at (0,0,0) rotated around the three axes in Y, Z, X order

CFrame.fromAxisAngle( Vector3 v, Number r)

Creates a rotated CFrame from a unit vector and a rotation in radians

CFrame.lookAt( Vector3 position, Number lookAt)

Creates a CFrame whose position is position, and whose whose lookVector is directed towards, or looking at lookAt

Properties

Member Description
Vector3 Position the positional component of the CFrame
Number X the positional component of the CFrame on the X axis
Number Y the positional component of the CFrame on the Y axis
Number Z the positional component of the CFrame on the Z axis
Vector3 LookVector the front-facing directional vector of the CFrame
Vector3 RightVector the right-facing directional vector of the CFrame
Vector3 UpVector the up-facing directional vector of the CFrame
Vector3 XVector the first column in the rotation matrix of the CFrame
Vector3 YVector the second column in the rotation matrix of the CFrame
Vector3 ZVector the third column in the rotation matrix of the CFrame


Methods

Method Description

CFrame CFrame:Inverse( )

returns the inverse of the CFrame

CFrame CFrame:ToWorldSpace( CFrame c)

returns a CFrame transformed from Object to World coordinates. Also works with tuples

CFrame CFrame:ToObjectSpace( CFrame c)

returns a CFrame transformed from World to Object coordinates. Also works with tuples

Vector3 CFrame:PointToWorldSpace( Vector3 v)

returns a Vector3 transformed from Object to World coordinates. Also works with tuples

Vector3 CFrame:PointToObjectSpace( Vector3 v)

returns a Vector3 transformed from World to Object coordinates. Also works with tuples

Vector3 CFrame:VectorToWorldSpace( Vector3 v)

returns a Vector3 rotated from Object to World coordinates. Also works with tuples

Vector3 CFrame:VectorToObjectSpace( Vector3 v)

returns a Vector3 rotated from World to Object coordinates. Also works with tuples

Tuple CFrame:GetComponents( )

or

Tuple CFrame:components( )

returns all components of the CFrame in the following order:

x, y, z, R00, R01, R02, R10, R11, R12, R20, R21, R22

Tuple CFrame:ToOrientation( )

or

Tuple CFrame:ToEulerAnglesYXZ( )

returns approximate angles of the part's orientation

Tuple CFrame:ToEulerAnglesXYZ( )

returns the approximate angles of the part's orientation ordered as Z, Y, X

Number CFrame:ToAxisAngle( )

returns the orientation of the CFrame in axis-angle representation

CFrame CFrame:Orthonormalize( )

returns a CFrame that went through the Gram-Schmidt process

Operators

Operator Description
CFrame * CFrame returns composition of two CFrames
CFrame * Vector3 returns Vector3 transformed from Object to World coordinates
CFrame + Vector3 returns CFrame translated by Vector3
CFrame - Vector3 returns CFrame translated by -Vector3



Advertisement