Limit camera rotation

Hello, I am trying to limit the camera rotation to 30 degrees to right and 30 degrees to the left. So the player can only rotate their camera 30 degrees to each direction. But I can’t do it. I already tried some scripts, but none of them worked. I even searched in the forum, but I couldn’t find anything related. The most I got was this script that limits the rotation to 30 degrees in only one direction.

local minRotation = -30
local maxRotation = 30
local lastRotation = 0

	local currentRotation = workspace.CurrentCamera.CFrame.LookVector
	local angle = currentRotation:Dot(,0,0))
	angle = math.deg(math.acos(angle))
		if angle > lastRotation then
		    if angle > maxRotation then
			   angle = maxRotation
		if angle < minRotation then
			angle = minRotation 
	lastRotation = angle
	local newRotaton =,0,math.sin(math.rad(angle)))
	workspace.CurrentCamera.CFrame =,workspace.CurrentCamera.CFrame.p + newRotaton)

Current result:

1 Like

I found an old script that may help you out x

		local Cam = Camera.CFrame:ToOrientation()	
		local Val = math.clamp(math.deg(Cam), -30, 30)
		Camera.CFrame = * CFrame.fromOrientation(math.rad(Val), math.rad(170), 0)	

It limits the camera’s movement to a limited angle on the X axis and prevents it from moving on the Y axis. But alas, it’s not smooth at all, and I haven’t found anything to make it completely smooth anywhere in the forum. Hopefully this can help you! xo

1 Like

This code only works in X direction, when I try to change to the Z direction it does nothing.

Z direction is roll angle, and player cameras do not move in the Z direction by default.
You should try changing that script to the Y direction.