What do you want to achieve? Keep it simple and clear!
I would like to get to know the components of the CFrame better
What is the issue? Include screenshots / videos if possible!
I don’t know her.
What solutions have you tried so far? Did you look for solutions on
the Developer Hub?
I have also searched on Wikipedia but no concrete answer.
I know that m11, m21 and m31 are the same as the right vector and the others form the top vector and the front vector, but what do they do when used separately and when should the components of the CFrame be used separately?
If you’re asking for specific examples in when you would use :GetComponents(), there really isn’t too much of a need to. You already explained what all of the components are individually. The first three values are the position values, and the following values are the values for the three unit vectors. This would make :GetComponents() useful, if it weren’t for the fact that all these are already properties of a CFrame value. CFrame.p, CFrame.RightVector, etc. will all do the job just fine.
If you’re asking when to use an individual component, that’s a bit of a different story. You still don’t need to use :GetComponents() as you could just use something like .UpVector, but you can read the individual coordinates of a unit vector to tell what direction a part is facing without having to worry about the orientation. If a part is facing upwards even a tad, then its UpVector.Y will print out as greater than 0. If the part is facing completely upwards, then it’ll print out as 1, and if facing down, it’ll print a negative number with a magnitude between 0-1.
I’ve rarely actually used this in coding (maybe once or twice), but it isn’t exactly useless to have these individual values from my experience, even if there may be an alternative method.
While destructing CFrames into components might seem not to have many use cases (I for my part have only done that once for a plugin), constructing from components is more interesting and useful.
Simple example: Given you want to draw a triangle between three points A, B and C using wedges and the angle at B is a 90° one, you know that vectors A->B (Mathematically AB = B - A) and B->C (BC = C - B) are perpendicular to another.
Using the vector cross, you can easily find a third vector to complete the rotation matrix.
RLua Vector3s have a cross function implemented, D = AB:Cross(BC).
Position equals the point between A and C, P = (A + C) / 2
Given these vectors you can position a WedgePart to match your triangle:
CFrame.new(P.X, P.Y, P.Z, D.X, AB.X, BC.X, D.Y, AB.Y, BC.Y, D.Z, AB.Z, BC.Z)
My personal use case for CFrame components: I have a plugin that allows me to click on parts to set them as zones/regions within my game. The plugin stores the position and rotation (using CFrame:GetComponents()) of these parts in a ModuleScript, which is then used by my ZoneService at runtime to construct a new CFrame to determine if parts or players are within the zone.