Hi! So I have a custom camera manipulation that makes a third person over the shoulder camera angle. It works perfectly fine but the camera will go through walls. Any idea on how I can solve this?

Part of the script (not all of the script):


camera.CameraType = Enum.CameraType.Scriptable
		character.Humanoid.AutoRotate = false
		local hrp = character:WaitForChild("HumanoidRootPart")
		
		local x = 0
		local y = 0
		
		local offset = Vector3.new(3, 2, 10)
		
		UserInputService.InputChanged:Connect(function(input, processed)

			if processed then return end

			if input.UserInputType == Enum.UserInputType.MouseMovement then

				x = x - input.Delta.X

				y = math.clamp(y - input.Delta.Y*0.4, -75, 75)


				hrp.CFrame = hrp.CFrame * CFrame.Angles(0, math.rad(-input.Delta.X), 0)
			end
		end)


		game:GetService("RunService").RenderStepped:Connect(function()

			UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter

			local A = UserInputService:GetMouseLocation()

			local ray = workspace.CurrentCamera:ScreenPointToRay(A.X, A.Y)

			character.HumanoidRootPart.CFrame = CFrame.new(character.HumanoidRootPart.Position, character.HumanoidRootPart.Position + ray.Direction * Vector3.new(1, 0, 1))
			local startCFrame = CFrame.new((hrp.CFrame.Position)) * CFrame.Angles(0, math.rad(x), 0) * CFrame.Angles(math.rad(y), 0, 0)
			local cameraCFrame = startCFrame:ToWorldSpace(CFrame.new(offset.X, offset.Y, offset.Z))
			local cameraDirection = startCFrame:ToWorldSpace(CFrame.new(offset.X, offset.Y, -10000))

			camera.CFrame = CFrame.new(cameraCFrame.Position, cameraDirection.Position)
		end)