Fandom

ROBLOX Wikia

CFrame

12,748pages on
this wiki
Add New Page
Comments0 Share

A CFrame, or Coordinate Frame, is a userdata item containing position and rotation data. It can be used to accurately position BaseParts through their CFrame property, which unlike Position, allows the part to be placed overlapping another part and 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 sequencially. 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.

Constructors

CFrames themselves are one of the Basic Types available in ROBLOX Lua. It can be called by using several different constructors.

Constructor Description

CFrame.new( )

Creates an identity CFrame

CFrame.new( Vector3 v)

Creates CFrame from offset v

CFrame.new( Vector3 v, Vector3 l)

Creates CFrame from offset v looking at point l

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)

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

CFrame.fromAxisAngle( Vector3 v, Number r)

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

Members

Member Description
Vector3 p the translation
Number x the x-component of translation
Number y the y-component of translation
Number z the z-component of translation
Vector3 lookVector returns the facing direction along each axis

Methods

Method Description

CFrame CFrame:inverse( )

returns the inverse of this 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

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

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.