Custom FPS camera tilts the wrong way

I’m trying to create a custom camera controller for a first-person game, but the camera “tilts” instead of “nodding” when it looks to the side.

rs.RenderStepped:Connect(function(dt)
	uis.MouseBehavior = Enum.MouseBehavior.LockCenter;
	delt = uis:GetMouseDelta();
	
	mX = math.rad(-delt.X);
	mY = math.rad(-delt.Y);
	
	mXA += mX;
	mYA = math.clamp(mYA+mY, math.rad(-80), math.rad(80));
	
	cam.CFrame = CFrame.fromEulerAnglesXYZ(mYA, mXA, 0);
end)

I tried using :ToObjectSpace but couldn’t figure out how to use it here. I also tried using sin and cos to switch between rotating the Y and Z axis based on the X but it was a little glitchy. So how could I stop it from tilting?
Any help is appreciated

Try using CFrame.fromOrientation instead.

cam.CFrame = CFrame.fromEulerAnglesYXZ(mYA, mXA, 0);

I didn’t know the order of the XYZ mattered, but ill try to look into it more thoroughly.

Thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.