How to get a CFrame's Angles X, Y and Z numbers?

I’m currently trying to learn how to use CFranes, but I’m still not able to understand how a CFrame’s orientation works.

I already know how to use CFrames to make a part match another part’s position:

while wait() do
   part1.CFrame = CFrame.new(part0.CFrame.X, part0.CFrame.Y, part0.CFrame.Z)
end

Now I want to do the same thing, but with orientation instead of position. I need to get a CFrame angle’s X, Y and Z numbers and I don’t know how to do that.

I would like to do something similar to this:

while wait() do
   part1.CFrame = CFrame.Angles(part0.CFrame.Orientation.X, part0.CFrame.Orientation.Y, part0.CFrame.Orientation.Z)
end

A CFrame stores a position and a 3x3 rotation matrix. You can get the rotational component of a CFrame in a couple different ways, either CFrame:GetComponents() which will give you the position and the 3x3 matrix or CFrame:ToEulerAnglesXYZ() which will give you the rotation in the form of euler angles. You can reconstruct the CFrame using EulerAngles with the CFrame.Angles constructor or simply use CFrame.new with what CFrame:GetComponents() gives you.

8 Likes

You can use:

CFrame:ToEulerAnglesXYZ() 

Also as CFrame contains a rotation matrix

CFrame:GetComponents ( ) -- x, y, z, R00, R01, R02, R10, R11, R12, R20, R21, R22

:slight_smile:

3 Likes

CFrame:ToEulerAnglesXYZ() is the solution to my problem, I tried it and it worked. So both of your replies are a solution, thanks for the help!

4 Likes