local RunService = game:GetService("RunService")
local camera = workspace.CurrentCamera
RunService:BindToRenderStep("UpdateLoop", Enum.RenderPriority.Camera.Value, function()
local rX, rY, rZ = camera.CFrame:ToOrientation()
local limX = math.clamp(math.deg(rX), -45, 45)--Restricts movement up and down
local limY = math.clamp(math.deg(rY), -45, 45) --Restricts movement to the sides
print(math.deg(rY))
camera.CFrame = CFrame.new(camera.CFrame.p) * CFrame.fromOrientation(math.rad(limX), math.rad(limY), rZ)
end)
Every thing works fine for angles -45 and 45 as you can see in the video but if I were to use for example values from 135 to 225 it wouldn’t work for example:
Rotation ranges from [-180] to [180] degrees. A slight adjustment to the limY clamp should do.
Going counter-clock wise, this is actually the area between 135 deg and -135 deg (180 - (250-180)), if I’m not mistaken. The clamp has to be broken into two parts: -135, -180 and 135, 180.
local RunService = game:GetService("RunService")
local camera = workspace.CurrentCamera
local clamp = math.clamp
local deg = math.deg
local rad = math.rad
RunService:BindToRenderStep("UpdateLoop", Enum.RenderPriority.Camera.Value, function()
local rX, rY, rZ = camera.CFrame:ToOrientation()
local limX = clamp(deg(rX), -30, 30)
local limY = rY < 0 and clamp(deg(rY), -180, -135) or clamp(deg(rY), 135, 180)
print(limY)
camera.CFrame = CFrame.new(camera.CFrame.p) * CFrame.fromOrientation(rad(limX), rad(limY), rZ)
end)