How to get the Z rotation using CFrame :GetComponents() function on roblox?

I need to get the z rotation of cframe matrix returned by the cframe :GetComponents() function. I know that the last 9 values returned by the function specify a 3X3 matrix denoting the rotation, but how would i get the z rotation, as well as what does each value in the rotational matrix is representative of.

1 Like

Until someone smarter than me replies here’s a really dumb way.

Have the script reference a part not necessarily parented to the workspace and set the part’s CFrame to your value and just grab the Part.Orientation.Z.

@VineyardVine
You are partially correct. CFrames have a CFrame:ToEulerAnglesXYZ() method which returns the X, Y and Z angles of its orientation.

The values of :GetComponets are a bit mixed compared to standard 4x4 transformation matrices (because that’s what actually a CFrame is under the hood), but they are all there.
The first 3 values are the values of the position vector.
The next 3 represent the x values of each direction vector (right,up,look)
Then their y values.
And finally their Z values.

Here’s a CFrame:
px, py, pz
rvx, uvx, lvx
rvy, uvy, lvy
rvz, uvz, lvz

Here’s a 4x4 matrix:
rvx, uvx, lvx, px
rvy, uvy, lvy, py
rvz, uvz, lvz, pz
0, 0, 0, 1

Another thing to note is that the LookVector actually points backwards, so you will have to negate it if you want to find where your part is really pointing.

4 Likes

its the camera i am trying to animate

thanks i will try this out now

Slight correction; the LookVector is where your part is pointing, it represents the normal of your part’s front face. Negating the look vector actually gets you the back vector.

True, but the negative direction in global coordinates.