CFrames are made of a x,y,z position as well as a rotation matrix. The rotation matrix is a 3x3 matrix containing 3 vector3s.
e.g.
1,0,0 - xVector
0,1,0 - yVector
0,0,1 - zVector
the first vector is the xVector, or RightVector. This is a unit vector that is facing right. If you ever select a part in roblox studio, then use the Move tool, this would be the red arrow that appears.
the second vector is the yVector, or UpVector. This is a unit vector that is facing upwards. The color of this arrow is green.
the third vector is a little more confusing. Generally speaking, forward is negative on the Z axis. However, if you ever see CFrame.LookVector
it is actually inverted. positive Z is forward. However, in our rotation matrix this shouldn’t be the case. The LookVector
is the facing direction of the part, but in the rotational matrix zVector
is the real forward direction. This arrow will appear blue.
Rotation matrices should be orthonormalized. This basically means every vector discussed aboved is 90 degrees of one another. The up vector is 90 degrees of the rightvector and lookvector, etc etc. Roblox, by default, orthanormalizes rotation matrices. So you dont need to worry about this. However, the rule that every vector should be 90 degrees of one another lets us use the cross product.
For example, lets say we have a rotational matrix like so
1,0,0
0,1,0
but the last one is unknown
luckily, since its orthanormalized, we can use the cross product of the first two vectors to get the final one.
(1,0,0):cross(0,1,0) = 0,0,1
so our rotational matrix is
1,0,0
0,1,0
0,0,1
tada! If we ever want to construct a CFrame from a rotational matrix, we can use the CFrame.fromMatrix operator.
Whenever you use CFrame.Angles, you aren’t using a rotational matrix, you’re using euler angles. Generally speaking, you want to stick to using rotational matrices to avoid issues with angular space, e.g gimble lock. Sticking to rotational matrices also is more performant, since computers are much better at running matrix multiplication than trig functions ontop of matrix multiplication.
If you’re more curious, I suggest you look into axis angle theorem and other really cool stuff.
if you have any questions, please ask!