How can I find the angular distance between two CFrames?
Let me explain better, given a CFrame “CFOrigin” and a CFrame “CFTarget”, how can I find the X, Y and Z values in the following equation?
CFOrigin * CFrame.Angles(X,Y,Z) = CFTarget
Well, you could find the CFrame by doing left side multiplication with CFOrigin:inverse() so it’s CFrame.Angles(X,Y,Z) = CFOrigin:inverse() * CFTarget and then use a function to grab the angles.
local mainPart = ?;
local otherPart = ?;
local differenceComplete = otherPart:ToObjectSpace(mainPart)
local differenceOrientation = differenceComplete - differenceComplete.p
local X,Y,Z = differenceOrientation:ToEulerAnglesXYZ()
The difference is the object space location of the second part.
This works when applied all together, but when I try, for example, to apply only the X component by getting the result :ToEulerAnglesXYZ() and using it as CFOrigin * CFrame.Angles(X,0,0) I get a weird and inconsistent result. Is there a way to get the rotation of a CFrame like Part.Orientation does?