How would I limit horizontal camera movement?

Hello! So I’m trying to make it where when in first person you can only look a certain radius to the left or right. Here is a vid of what I mean.

Sorry if that doesn’t make much sense.
I’ve look through the camera module and I can’t seem to find where I can edit this.

Every renderstep you can just clamp the cframe values of the camera. There are tutorials on Understanding CFrames.

1 Like

Hello! Thanks for the reply. I tried this:

local Connection = RunService.Heartbeat:Connect(function()
		local X, Y, Z = Cam.CFrame:ToOrientation()
		local Lim = math.clamp(math.deg(X), -240, 240)
		Cam.CFrame = * CFrame.fromOrientation(math.rad(Lim), Y, Z)

But it doesn’t seem to be doing anything.
Sorry for the trouble.

Perhaps it will be useful


local Player = game.Players.LocalPlayer
local Character = Player.Character
local RootPart = Character.HumanoidRootPart

local MaxCamAngX= 45 -- 80 is default
local MaxCamAngY= 60

game["Run Service"].RenderStepped:Connect(function()

	local MinAngX = RootPart.Orientation.Y-MaxCamAngX
	local MaxAngX = RootPart.Orientation.Y+MaxCamAngX
	local MinAngY = RootPart.Orientation.Y-MaxCamAngY
	local MaxAngY = RootPart.Orientation.Y+MaxCamAngY

	local X, Y, Z = workspace.CurrentCamera.CFrame:ToOrientation()

	local LimX = math.clamp(math.deg(X), MinAngX, MaxAngX)
	local LimY = math.clamp(math.deg(Y), MinAngY, MaxAngY)

	workspace.CurrentCamera.CFrame = * CFrame.fromOrientation(math.rad(LimX), math.rad(LimY), Z)


1 Like