I need help understanding this

Hello, i am having trouble understanding the difference between Vectors and Cframe, i can t understand the difference can anyone explain

3 Likes

A CFrame defines the position and orientation of a part.

It is a matrix that contains the components of four vectors. One of the vectors is a position vector and the other three are direction unit vectors that are perpendicular to each other. These vectors are called RightVector, UpVector and BackVector. A CFrame doesn’t actually have a BackVector property but CFrame.LookVector is just the opposite of BackVector (LookVector = -BackVector).

Each of the four vectors has X, Y and Z components which is twelve numbers in total. A CFrame actually represents a 4x4 matrix but the four remaining numbers are constants so I’m pretty sure they aren’t stored.

2 Likes

A vector is a point or a direction. It is used to define a point in a dimension like the 3rd dimension or the 2nd.

Example:

Vector3.new(5,10,-5) -- A point 5 studs to the right, 10 studs up and 5 studs infront of the world origin that is 0,0,0

Vector3.new(0,1,0) -- A direction in the upwards direction.

How to differentiate directions from points? It’s just a measure of how the code is written. Basically dependent on context.

A CFrame is a cluster of vectors, mainly 4 of them in a such a way that those vectors make the position and the rotation of an object.

They usually have 4 vectors, a position vector and 3 directional vector which are the right vector (indicated the right side), up vector (indicated the up side) and the look vector (indicated the front side).

Now, while coding you don’t have to use so many vectors, usually you just need a rotation and a position. For example:

CFrame.new(0,10,-5)*CFrame.Angles(0,math.rad(45),0) -- A CFrame with the position 10 studs above and 5 studs in front of the world origin rotated at an angle of 45 degrees on the Y axis.

CFrame.new(0,math.rad(90),0) * CFrame.new(0,0,-10) -- A CFrame which was rotated FIRST then move which means it would be 10 studs on the right of the world origin as we rotated it first and then moved it in front. Kind of like you rotated to your right side then walked 10 meters.
1 Like

i understood now what is a vector but not a cframe it s kinda confusing.

1 Like

Basically, you can take an example of yourself. Your rotation and your position is basically a cframe.

Say you are standing 10 meters in front of your bed. Your CFrame would be

CFrame.new(0,0,-10)

From your bed.

Let’s say now you turned 90 degrees in the clockwise direction. Your CFrame would be:

CFrame.new(0,0,-10)*CFrame.Angles(0,math.rad(90),0)

math.rad basically converts an angle in degrees to radians.

Now let’s say you are on your bed again, you turned 90 degrees clockwise then moved 10 meters forward relative to your point of view so now you see that you are on the right side of the bed. Your CFrame now would be:
Let’s say now you turned 90 degrees in the clockwise direction. Your CFrame would be:

CFrame.Angles(0,math.rad(90),0)*CFrame.new(0,0,-10)

Do you understand now?

CFrame = Position but it has orientation with it