Using :ToOrientation() on a CFrame created by :fromMatrix() gives the angles (0,0,0) unless set on a part

I’m trying to get the radians of each axis so I can clamp them, but when I do so, I get (0,0,0). However, when I set the part’s CFrame to the one created by :fromMatrix(), it gives me the desired radians. The script is making the part be flushed with the base of the other part. See below:

image

local part = script.Parent

function detectGround(p,ignore)
    local ray = Ray.new(p.Position,-p.CFrame.UpVector.Unit*500)
    local hitPart, hitPosition,normal = workspace:FindPartOnRay(ray, ignore)
    if hitPart then
        return normal,hitPosition
    end
end

local normal, hitpos = detectGround(part,part)

if not normal then return end

local rCF = CFrame.lookAt(part.CFrame.Position,part.CFrame.Position+part.CFrame.LookVector)

local NormalCFrame = CFrame.fromMatrix(hitpos+normal,rCF.lookVector:Cross(normal),normal,-rCF.lookVector) --gets the NormalCFrame that is flush with the part

local x,y,z = NormalCFrame:ToOrientation() --the radians of Normal CFrame

print(math.deg(x),math.deg(y),math.deg(z)) --Gives (0,0,0)

part.CFrame = NormalCFrame --setting CFrame of the part to NormalCFrame

x,y,z = part.CFrame:ToOrientation() --the radians of the part's CFrame now

print(math.deg(x),math.deg(y),math.deg(z)) --Gives (~22.5,0,0), which is what I'm looking for...

I don’t really understand why it is doing this… I’ve tried a lot of things, yet none of them seem to be working out, and the only solution as of now is to create a “dummy” part and read the CFrame of that when it is set to NormalCFrame.

Hey @Project_Aurora!

I have to be honest. I just do not understand what you’re asking. What is the issue? I see what’s currently happening, what instead is the desired result?

Sorry I’m really just not quite getting it, thanks.

I’m trying to get the x,y, and z radians of NormalCFrame for clamping purposes so the x and z axis don’t go over -75 or 75 degrees. Currently it won’t clamp in this state, however, I’m just trying to get the angles so I can still replicate the CFrame. When I did NormalCFrame:ToOrientation(), I expected it to give me 22.5 deg in radians on the x axis, however, it gave me 0 for x,y, and z. After I set the CFrame to the part and did part.CFrame:ToOrientation(), it gave me exactly what I needed. Though, I expected that doing NormalCFrame:ToOrientation(), would yield the same result… which it didn’t.