I need help to understand CFrame

CFrame is a matrix made up of 12 float numbers which consist of rotation and position. Rotation is basically orientation, consisting of 3 numbers; x, y, and z. The position also consists of 3 numbers; x, y, and z.

However, CFrames also include directional vectors, vectors that have a length of 1. Those directional vectors are LookVector, UpVector and RightVector. Also note that directional vectors are unitized and that is t
he reason they have a length of 1.

LookVector is the forward part of a CFrame, RightVector being the right and UpVector being the up. However, it’s different when they are negative:

Remember that -LookVector is back, -RightVector is the left and -UpVector is down [ONLY IF IT’S NEGATIVE].

Whenever you construct a new CFrame, it will always be 0, 0, 0. However, you should provide arguments i.e x, y and z. For e.g:

(Also keep in mind that CFrames are object space while Positions are world space)

CFrame.new(0, 5, 0) --> We position the CFrame 5 studs on the y axis

CFrame.new(1, 5, 0) -- > Contructs a new CFrame 1 stud on the x, 5 on the y and 0 on the z axis

Let’s take some examples from code:

local part = Instance.new("Part") -- create the part
part.CFrame = CFrame.new(0, 5, 0)
part.Parent = workspace

In the code above, we tell the part’s CFrame to be 5 studs on the y axis.

Next example:

local part = Instance.new("Part") -- create the part
part.CFrame = part.CFrame.LookVector * 2 -- look vector is a unit
part.Parent = workspace

Now this code makes use of the directional vectors. Remember that you can set a CFrame to a vector and directional vectors are basically Vector3s. The above code set’s a part’s CFrame to it’s look vector multiplied by 2.

Vector3s are 3D, while Vectors are 2D. Z axis in Vectors don’t exist.

It won’t have the same orientation since CFrame’s have a default orientation of 0, 0, 0. It will only keep the orientation if it’s multiplied.

I was referring to code that I posted earlier:

Part.CFrame = Character.HumanoidRootPart.CFrame * CFrame.new(0, 0, 5)

In that example ‘Part’ would end up with the same orientation as ‘Character.HumanoidRootPart’, but offset by 5 studs due to the transformation.