Issues - Limit camera do not look at legs in fps mode

How can I limit the vision of my player so that he cannot look at his legs?

I made the player in first person using:
player.CameraMode = Enum.CameraMode.LockFirstPerson

but now I would like to limit your visual field so that you cannot look at your legs in the first person

I would like to put a limit when looking down and a limit when looking up, in the reference images it is understood a little better what I want to achieve, someone could give me a hand please

In short:
I want to do in the first person FPS the player when looking down (camera down) cannot look at his legs (have a limit), how can I do it?

You may be able to use math.clamp() on the Camera’s CFrame

You should be able to clamp the camera’s rotation using :BindToRenderStep. You’d also probably have to use trial and error to define the lower bound as I’m not too sure how to do the math.

Try this, parent to StarterCharacterScripts:

local runService = game:GetService('RunService')

local torso: BasePart = script.Parent:WaitForChild('Torso')

local camera = workspace.CurrentCamera

local cameraClampMin = -30
local cameraClampMax = 90

local function clampOrientation()
	local cframe = workspace.CurrentCamera.CFrame
	local rX,rY,rZ = cframe:ToOrientation()
	local clamp = math.clamp(math.deg(rX), cameraClampMin, cameraClampMax)
	workspace.CurrentCamera.CFrame = CFrame.new(workspace.CurrentCamera.CFrame.p) * CFrame.fromOrientation(math.rad(clamp), rY, rZ)
	for i,v in pairs(script.Parent:GetChildren()) do
		if v:IsA('BasePart') and v.Name ~= 'Torso' then
			v.LocalTransparencyModifier = 0
		end
	end
end

runService:BindToRenderStep('ClampCamera', Enum.RenderPriority.Camera.Value, clampOrientation)
3 Likes

Thank you! this is super useful! a question, what does this part do exactly? And how could I modify the maximum of the limit and the parts to hide?

It essentially just removes the transparency of the parts (which happens when you zoom in and all parts of your character disappear).

You should be able to do it with the cameraClampMax variable in my code sample

Best practice would probably be to use a table, something like this should work (might error, haven’t tested it):

local partsToHide = {
    'Torso';
    'Head'
}

-- ...

        if v:IsA('BasePart') and not table.find(partsToHide, v.Name) then
			v.LocalTransparencyModifier = 0
		end

Local script in starter player scripts:

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)
	camera.CFrame = CFrame.new(camera.CFrame.p) * CFrame.fromOrientation(math.rad(limX), rY, rZ)
end)

Found here.

1 Like