How can I clamp the camera's Y rotation?

I’ve tried using math.clamp on the XVector.X value but the outcome was not what I was looking for, I’ve also tried this which fails horribly.

local _, yaw, roll = camera.CFrame:ToEulerAnglesYXZ()
camera.CFrame = CFrame.new(camera.CFrame.Position) * CFrame.Angles(math.clamp(yaw,-0.5,0.5),yaw,roll)

Any suggestions?

1 Like

There is a default camera module in the Player Scripts, clone it and change the min values in the module to modify camera movement.

1 Like

It needs to be enabled and disabled easily, not something permanent for the entire game. Also I am pretty sure the camera module you are referring to only works on the X axis.

Yeah, the one I’m referring to can be modified - and is for all axis including (x and z as well).

You should be able to manually limit it with some code like this:

local RunService = game:GetService("RunService")

local function directlyAfterCamera(delta)
	-- Code in here will run directly after the default Roblox camera script
	-- Clamp the camera's rotation to something within the limits here
end

RunService:BindToRenderStep("After camera", Enum.RenderPriority.Camera.Value + 1, directlyAfterCamera)

To stop it, you could either disconnect the connection or just use an if statement inside the function to check if the limits are enabled.

2 Likes

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