hey,I’m just wondering how would i find a rotation between a part rotation and a camera rotation because i kept getting error when substracting 2 cframe.rotation
Have you tried to use the :inverse
method on your part’s CFrame, and multiply it by your camera CFrame?
that’s not the thing im just trying to get the gap between two rotation but i got an error everytime
part.CFrame.LookVector-camera.CFrame.LookVector try this formula
But that is what you need to do? You cant Subtract a CFrame
, You need to Multiply them together which is how the follow works:
Lets say I have two parts here, one is p0
, and the other is p1
, you need to get the Difference in Rotations of both CFrames, which to do that is basically what @Valkyrop said: (p0.CFrame:Inverse() * p1.CFrame
), you then need to get the Rotation from the new CFrame, but in a XYZ format instead of… all those numbers, which is as simple as newCFrame.Rotation:ToOrientation()
, the following function (ToOrientation
) will translate the Rotation Part of the CFrame, into a usable number using radians under the XYZ format, the function however returns three values, so you need to have three variables to get the values, if you want to convert radians to degrees, you use math.deg
to do this, the Result will not be “exact”, but it will be close.
Code of what is being said:
-- lets say these are the two parts
local p0 = workspace.Part1
local p1 = workspace.Part2
local cf = (p0.CFrame:Inverse() * p1.CFrame) -- Inverse p0 CFrame multiplied by p1 CFrame
-- if you had a CFrame with the Position or Rotation of 1, 1, 1, :Inverse() would make it -1, -1, -1
local x,y,z = cf.Rotation:ToOrientation() -- Translates Rotation CFrame to XYZ values
print(math.deg(x), math.deg(y), math.deg(z)) -- values converted to degrees
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.