How do i make the player couldn’t rotate the camera 360 degrees

What do you want to achieve? Keep it simple and clear!

So i was making a script where if player is climbing a ladder the characters humanoid autorotate turned into false.

so the player couldn’t move out of the ladder by facing the camera to the left or right.

but now the player could look freely 360 degrees, so i wonder how do i make it so that the players camera couldn’t look left and right totally so it looks realistic.

heres a video explaining my statement:

2 Likes

First, this method comes with one problem and that is looking up and down and is not possible, you may be able to figure out and im pretty sure its something super simple and im just missing it, its here where I’m setting the new cframe but when I try to set its rotation of its x, it doesn’t like that so I left it as is.

camera.CFrame = CFrame.new(camera.CFrame.Position) * CFrame.Angles(0, rotationY, 0) 

local camera = game.Workspace.CurrentCamera

local maxRotation = 90
local minRotation = -90

local a,b,c 
a =camera:GetPropertyChangedSignal("CameraType"):Connect(function()
	camera.CameraType = Enum.CameraType.Scriptable
	a:Disconnect()
end)

b = camera:GetPropertyChangedSignal("CameraSubject"):Connect(function()
	if camera.CameraSubject then
		camera.CameraType = Enum.CameraType.Scriptable
	end
	b:Disconnect()
end)

c = camera:GetPropertyChangedSignal("CFrame"):Connect(function() -- Note that using this method will cause an error due to a few technical reason but the main one being that were changing the cframe of the camera when the cframe of the camera is changed which creates a "infinite loop" to the computer but you can just disconnect it by doing 'c:Disconnect'

	local currentCFrame = camera.CFrame
	local rotationX, rotationY, rotationZ = currentCFrame:ToEulerAnglesYXZ()
	rotationY = math.clamp(rotationY, math.rad(minRotation), math.rad(maxRotation))
	camera.CFrame = CFrame.new(camera.CFrame.Position) * CFrame.Angles(0, rotationY, 0)
end)
-- Alternative method if you dislike the error but it might use more resources, I don't know much either method takes
--[[

game:GetService("RunService").RenderStepped:Connect(function()
	local currentCFrame = camera.CFrame
	local rotationX, rotationY, rotationZ = currentCFrame:ToEulerAnglesYXZ()
	rotationY = math.clamp(rotationY, math.rad(minRotation), math.rad(maxRotation))
	camera.CFrame = CFrame.new(camera.CFrame.Position) * CFrame.Angles(0, rotationY, 0)
end)
]]

hmm, everything works but it only works if the ladder is facing in front of the players position when spawn.

if the ladder is behind the player when spawn, when climbing it makes the camera clamps behind the player, instead of well facing the ladder, so it depends on the world axis maybe? idk.

how do i fix this?

I used bind to renderstep by the way.

hello? can you respond me, character limitsss