The “rotation” component of a cframe can be defined as:
local cf = part.CFrame
local rotation = (cf - cf.Position)
Here is the expanded version
local cf = script.Parent.CFrame
local UpVec = cf.UpVector
local RightVec = cf.RightVector
local BackVec = -cf.LookVector
local rotation = CFrame.new(0,0,0,RightVec.X, UpVec.X, BackVec.X,RightVec.Y, UpVec.Y, BackVec.Y,RightVec.Z ,UpVec.Z,BackVec.Z)
Now that’s just “CFrame rotation” without the position applied , which means that to apply this to another CFrame, in case you wanted to mimic rotation across parts, we must multiply our rotation by the part’s position that we are dealing with first:
local NewCFrame = CFrame.new(pos) * rotation
However this isn’t the same thing as “changing a part’s Orientation”, because Orientation is applied in ZXY
order, so the CFrame equivalent of orientation is a bit different:
local cf = part.CFrame
local rotation = (cf - cf.Position)
local rx, ry, rz = rotation:ToOrientation()
local orientation = Vector3.new(math.deg(rx), math.deg(ry),math.deg(rz))
And because the position component of a CFrame doesn’t make a difference whether it’s left in or out of the equation when using ToOrientation
or really “anything dealing with rotation” in that matter we can take out the (cf - cf.Position)
and just use the full CFrame, so that our final simplified version becomes:
local cf = script.Parent.CFrame
local rx, ry, rz = cf:ToOrientation()
local orientation = Vector3.new(math.deg(rx), math.deg(ry),math.deg(rz))
Also here are some links to some useful wiki pages: