How would i go about limiting the Cameras Y axis rotation for a First person game?

So, I’m attempting to make a survival game, and basically I want to limit the cameras Y axis rotation so you cant look down all the way, and you cant look up all the way either.

I’m rendering the legs of the character and want them to look good when looking down, and add to the overall realism of the game by limiting the movement of the camera.

[What i want for camera limits]


[What is currently in place, which is nothing]

I have searched the dev forum for anything, but everything I found seems to be used for third-person games, not first person.

I barely understand math functions and somewhat understand CFrames, so any and all help with limiting the camera as I want is greatly appreciated.

you can probably use math.min, math.max, or math.clamp for what you are trying to do

Again,

By this I mean I can use them, barely.

I havent messed around with camera manipulation before, and I also dont want the camera to be locked down, I want the player to be able to freely look around as usual, just with the limits in place.

Also:

Thanks for the help, but it wasnt too helpful to me. I’ll certainly look into those though!

its easy, only took me 30 minutes to write 19 lines of code

-- client thing
-- I dont know where

local RunService = game:GetService("RunService")
local Camera = workspace.CurrentCamera

local MinAngle = math.rad(-50) --the lower the lower you can see
local MaxAngle = math.rad(81) -- extra setting for fun

RunService.RenderStepped:Connect(function()
	local YAngle = Camera.CFrame:ToOrientation()
	local CorrectedAngle = 0

	if YAngle > MaxAngle then  
		CorrectedAngle = MaxAngle - YAngle
	elseif YAngle < MinAngle then
		CorrectedAngle = MinAngle - YAngle
	end 

	Camera.CFrame *= CFrame.Angles(CorrectedAngle, 0, 0)
end)
7 Likes

Thank you so much! I would have had no clue how to do this myself!

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