Whats the difference between CFrame.Angles And Cframe:ToEulerAnglesXYZ

I was wondering because I used both methods for a mouse aimed projectile and ToEulerAngles worked like a charm but CFrame.Angles was interesting to say the least

2 Likes

they are the same, it even says so on the ToEulerAnglesXYZ description

3 Likes

CFrame.Angles or CFrame.fromEulerXYZ constructs a cframe rotation using the given angles. You access this using the CFrame library.

local cf = CFrame.Angles(math.rad(45), 0, math.rad(180))

CFrame:ToEulerAnglesXYZ or CFrame:ToEulerAngles converts a rotated CFrame into Angles. You can access this from a CFrame object.

local x, y, z = cf:ToEulerAnglesXYZ()
print(math.deg(x), math.deg(y), math.deg(z)) -- 45.0000001 0 -179.99999

The results from the print is not exactly the numbers we used but similar, this is because of floating point error. You can use math.round to fix it, but it’s not really necessary.

2 Likes

lol i think angles might have worked but i forgot to add the math.rad
smh

1 Like

Any particular reason why the 180* angle was converted into a negative number?

1 Like

So you noticed that 45 degrees increased by 0.00001. That is the same for the 180 degrees, it also increased by 0.00001. But, degrees do not usually go beyond 180 degrees. Once it reaches past 180 degrees or half the circle, it will start counting at -180 degrees. If 180 is equal to -180 degrees, 180.00001 is also equal to -179.99999.
image

5 Likes