Prevent a camera from looking up

I want to prevent the player from looking up, but it keeps glitching out because the mouse does not lock fast enough:


local function CameraAngle(CurrentCamera: Camera): boolean
	local LookVector = CurrentCamera.CFrame.LookVector.Unit
	local UpVector =, 1, 0)

	if LookVector:Dot(UpVector) <= 0 then 
		return true
		return false
local Angle = CameraAngle(self.CurrentCamera)
	if Angle then 
		UserInputService.MouseBehavior = Enum.MouseBehavior.Default
		self.CurrentCamera.CFrame = self.CameraPart.CFrame * CFrame.Angles(
			math.rad(((self.Mouse.Y - self.Mouse.ViewSizeY / 2) / self.Mouse.ViewSizeY) * -self.Tilt),
			math.rad(((self.Mouse.X - self.Mouse.ViewSizeX / 2) / self.Mouse.ViewSizeX) * -self.Tilt),
		UserInputService.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
		self.CurrentCamera.CFrame = self.CameraPart.CFrame

Is there a better way to rework this entire piece of code? Thanks.

I’m not super well versed in CFrame math and Angles, but you might be able to just clamp your calculations for the CFrame.Angles so the angle’s never exceed a specific number.

1 Like

I should have thought of this :laughing: !

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