Custom camera gets messed up when colliding

I’m working on a custom camera and it works fine… until the player collides with parts, which then causes the camera to mess up. The more and more a player collides with objects, the more and more the camera is mispositioned.

Camera before collision:
https://gyazo.com/29ca69778739565cacc70d9d8490e96f

After Collision:
https://gyazo.com/97836a28afe8cc2a368a724546e5d600

Camera Script (in startercharacterscripts):


local UIS = game:GetService("UserInputService")

local cam = workspace.CurrentCamera
cam.CameraType = Enum.CameraType.Scriptable

local mouse = game.Players.LocalPlayer:GetMouse()

local c = script.Parent

local hum = c:WaitForChild("Humanoid")
hum.AutoRotate = false

local hrp = c:WaitForChild("HumanoidRootPart")

local x = 0
local y = 0

local offset = Vector3.new(2,1,8,7)

UIS.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()
	if game.Players:GetPlayerFromCharacter(c).PlayerGui.StartMenu.PlayBtn.Visible == true or game.Players:GetPlayerFromCharacter(c).PlayerGui.Customization.CharacterFrame.Visible == true then return end
	UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
	
	local startCFrame = CFrame.new((hrp.CFrame.Position)) * CFrame.Angles(0,math.rad(x),0) * CFrame.Angles(math.rad(y),0,0)
	local camCFrame = startCFrame:ToWorldSpace(CFrame.new(offset.X,offset.Y, offset.Z))
	local camDirection =  startCFrame:ToWorldSpace(CFrame.new(offset.X,offset.Y,-10000))
	
	cam.CFrame = CFrame.new(camCFrame.Position, camDirection.Position)
	
	mouse.Icon = "rbxassetid://5216789017"
	
end)