Setting a single CFrame orientation value

Im working on a custom camera with no rotation limits and im having an issue when the camera will be offset a bit on the Z axis, which is really annoying and i cant figure out how to set only the Z orientation to 0 in the cameras CFrame

Ive attached a video showing how the camera is offset a bit:

heres the code I’ve currently got:

	local delta = uis:GetMouseDelta()
	local x = delta.X
	local y = delta.Y
	local CamCFrame = cam.CFrame * CFrame.fromOrientation(math.rad(-y),math.rad(-x),math.rad(0))
	local cX, cY, cZ,R00, R01, R02, R10, R11, R12, R20, R21, R22 = CamCFrame:GetComponents()
	cam.CFrame =
		R00, R01, R02, R10, R11, R12, R20, R21, R22
1 Like

How are you rotating the character itself? Can you just set the camera CFrame to the CFrame of the head?

the character is a body gyro changing based on the cameras CFrame