Camera that Only Allow Players to Move it Horizontally

I would like to have a camera that can only be moved horizontally, and not up-and-down.

The script that I have tested is working but overrides when the camera is on a cutscene, it also glitches a bit when the player tries to move the camera vertically.

Here is the script:

function Camera()
	local x,y,z = cam.CFrame:ToEulerAnglesXYZ()
	cam.CFrame = CFrame.new(cam.CFrame.Position) * CFrame.Angles(0,y,0)
end

runService.RenderStepped:Connect(Camera)

Also, will it be correct to use the CurrentCamera? Or are there better options?

I do not have much idea in scripting, so every response is appreciated. Thank you!

The glitching is caused because the default camera scripts are updating the y position before you are resetting it, causing a slight jitter. I can provide a better script but before that, could you specify whether the camera is in fp or third person?

The camera is in 3rd person, but can be zoomed into first person because the player can freely move it. I just want to limit their camera movement from up and down.

Advance thank you for your help!

It’s a simple fix tbh, just run your script after the Roblox camera updates using BindToRenderStep

function Camera()
	local x,y,z = cam.CFrame:ToEulerAnglesXYZ()
	cam.CFrame = CFrame.new(cam.CFrame.Position) * CFrame.Angles(0,y,0)
end

runService:BindToRenderStep("CustomCamera", Enum.RenderPriority.Camera.Value + 1, Camera)

Thank you! It works better, but somehow, it still overrides the cutscenes. I’ll try to fix the script of cutscenes instead. Thank you again!

Wdym by that? If it interferes with the cutscene just unbind the function from render step.

RunService:UnbindFromRenderStep("CustomCamera")
1 Like

That works perfectly, thank you!

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