Weird Tilting Camera Behavior

Hi all, I’ve been searching for a solution to this issue for some time now but couldn’t find anything. Basically I’m trying to make a camera rotate with the Delta from the user’s mouse, but the camera starts tilting weirdly at a certain point.

Ideally it should just be a view moving horizontally and vertically and not tilt like it is in the video. I don’t really have a firm grasp on what CFrame.Angles() actually is doing in this case, though I know to achieve this the Z axis needs to be somehow calculated but I don’t know how to do so.

Here’s a snippet my current code:

RS.RenderStepped:Connect(function(Time)
	local RatioX, RatioY = Delta.X/Mouse.ViewSizeX * 0.5, Delta.Y/Mouse.ViewSizeX * 0.5
        self.Camera.CFrame = self.Camera.CFrame * CFrame.Angles(0, -RatioX, 0) * CFrame.Angles(-RatioY, 0, 0)
end)

Any help would be greatly appreciated

You could set the camera’s CFrame to a new CFrame containing the current position of the camera, and the position + the LookVector of the camera, which would essentially reset the Z axis. This goes after the camera’s CFrame is set.

self.Camera.CFrame = CFrame.new(self.Camera.CFrame.Position, self.Camera.CFrame.Position + self.Camera.CFrame.LookVector)
1 Like

A better approach would be to do this:

local x = DeltaX * SENSITIVITY
local y = DeltaY * SENSITIVITY
self.Camera.CFrame = CFrame.new(self.Camera.CFrame.Position) * CFrame.Angles(0, x, 0) * CFrame.Angles(y, 0, 0)

Rotations are applied in local space of the current CFrame, or they’re applied relative to the current CFrame, as you might say - Euler angles can get pretty wack sometimes

2 Likes

A very viable solution thank you!!

Wish you could just apply angles to part CFrames without any other stuff going on… Thanks for the clarification and solution!