Camera CFrame orientation not being set as expected

I made a function that takes a angle in radians and sets the orientation of the Camera CFrame’s Y to that value, while preserving everything else. These prints are expected to match.
14:59:09.840 -15.000000417413027 90.00000250447816 0
14:59:09.840 6.482066111907466e-07 90.00000250447816 -15.000000417413027

This is the entirety of the function, angle is in radians:

local cameraCFrame = camera.CFrame
local xRot, _, zRot = cameraCFrame:ToOrientation()

print(math.deg(xRot), math.deg(angle), math.deg(zRot))
camera.CFrame = CFrame.new(cameraCFrame.Position) * CFrame.Angles(xRot, angle, zRot)

local xRot, yRot, zRot = camera.CFrame:ToOrientation()
print(math.deg(xRot), math.deg(yRot), math.deg(zRot))

1 Like

:ToOrientation() returns angles in a YXZ order, not XYZ.

2 Likes

After making an adjustment to change that I am getting a less confusing result, but still a non matching one.

With an intial orientation of -15, 90, 0 when veiwing the cameras cframe of my player and a angle equal to 90 degrees, I am expecting the result to be -15, 180, 0 or -15, -180, 0. Instead I now get:
-90 90 90
0 90 0

This is the updated code
local cameraCFrame = camera.CFrame

local xRot, _, zRot = cameraCFrame:ToEulerAnglesXYZ()
print(math.deg(xRot), math.deg(angle), math.deg(zRot))

camera.CFrame = CFrame.new(cameraCFrame.Position) * CFrame.Angles(xRot, angle, zRot)

local xRot, yRot, zRot = camera.CFrame:ToEulerAnglesXYZ()
print(math.deg(xRot), math.deg(yRot), math.deg(zRot))

1 Like