How do i find how many degrees a part is rotated from a CFrame, but i want it to only return 1 axis so basically it should return a number. Does anyone know which function does this
local cf = part.CFrame -- Replace with your CFrame
local _, yRotation, _ = cf:ToEulerAnglesYXZ() -- Extract the Y-axis rotation
local degrees = math.deg(yRotation) -- Convert radians to degrees```
what are euler angles? i cant understand the defination online
EulerAnglesYXZ
just gives the rotations like the Orientation
property does, except in “radians”, which need to be converted to degrees with math.deg
.
local myCFrame = CFrame.Angles(0, math.rad(90), 0)
local _, yRadians, _ = myCFrame:ToEulerAnglesYXZ()
-- prints "90 degrees"
print(math.deg(yRadians), "degrees")
ohhh ok ok. thank you for the explaination
Rotations can be described in different manners. Roblox uses CFrames internally, which are matrices (from linear algebra) that have a position component (Position’s X, Y and Z coordinates) and a rotation component, consisting out of 9 numbers.
Euler angles on the other hand may be easier to work with. They’re simply the 3 orientation numbers mentioned in the reply above. Euler angles describe how you would move from ‘no rotation’ to the given rotation by spinning an object along its X, Y or Z axis, comparable to how an airplane’s rotation is described by yaw, pitch and roll.
The downside of Euler angles is that the order in which you rotate along the X, Y and Z axis ends up giving different results. That’s why for example both a CFrame:FromEulerAnglesXYZ()
method and CFrame:FromEulerAnglesYXZ()
method exist. They return how much you would need to rotate from a default rotation to end up at the CFrame’s rotation if you apply the rotation in that specific order along the axes.