22,874 Pages

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.

One interesting fact is that anything with a property that is a CFrame value, for example, the CFrame property of a BasePart object, is hidden. The "Value" property of a CFrameValue is also hidden, thus needing to be modified from a Script.

## Contents

### 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( )

Creates CFrame from offset v

CFrame.new( , )

Creates CFrame from offset v looking at point l

CFrame.new( , , )

Creates CFrame from offset (x, y, z)

CFrame.new( , , ,
Number qx, Number qy, Number qz, Number qw)

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

CFrame.new( , , ,
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( , , )

or

CFrame.Angles( , , )

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

CFrame.fromAxisAngle( , )

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

### Members

Member Description
the translation
the x-component of translation
the y-component of translation
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( )

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

CFrame CFrame:toObjectSpace( )

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

Vector3 CFrame:pointToWorldSpace( )

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

Vector3 CFrame:pointToObjectSpace( )

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

Vector3 CFrame:vectorToWorldSpace( )

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

Vector3 CFrame:vectorToObjectSpace( )

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

Community content is available under CC-BY-SA unless otherwise noted.