Need help with camera clipping

Hello, I have a problem with my camera clipping through walls.
Video showcase:

Script I used:

local RunService = game:GetService("RunService")

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local head = character:WaitForChild("Head")
local humanoid = character:WaitForChild("Humanoid")
local camera = workspace.CurrentCamera

RunService.RenderStepped:Connect(function()
	local isFirstPerson = (camera.CFrame.Position - head.Position).Magnitude < 1.6
	
	if isFirstPerson then
		humanoid.CameraOffset = Vector3.new(0,0,-1.6)
	else
		humanoid.CameraOffset = Vector3.new(0,0,0)
	end
	
	for _, v in character:GetChildren() do
		if v:IsA("BasePart") and v ~= head then
			v.LocalTransparencyModifier = 0
		end
	end
end)

I do not have any idea how to fix it.

You are directly offsetting the camera forward. The camera is in front of the acutal player’s head so you will always be able to see through walls like that.
You could implement a ray check and adjust the distance offset of the camera that way.

1 Like