Need some help with camera collisions

Hi. I’ve been creating a strafe controller for my game, however, I can’t seem figure out a reliable camera collision system. It works as intended when colliding with the ground, though clips into walls via a “snap” effect.

Here is a video of what it looks like:
https://gyazo.com/55a792cd09d7e3e660c952c03a0a124b

Here’s the portion of code for the camera:

	local desiredCF = newHumRootCF * CFrame.Angles(math.rad(-TotalPitch), 0, 0) * CAMERA_OFFSET
	
	local origin = (Character.HumanoidRootPart.CFrame * CAMERA_OFFSET).Position
	local collisionRay = Ray.new(origin, desiredCF.Position - origin)
	local hitPart, hitPosition, normal = game.Workspace:FindPartOnRay(collisionRay, Character, false, true)
	
	if hitPart then
		desiredCF = (desiredCF - (desiredCF.Position - (hitPosition)) + normal)
	end
	
	local newCF = (LastCameraCF or desiredCF):Lerp(desiredCF, dt * CAMERA_DAMPING)
	
	CurrentCamera.CFrame = newCF
	LastCameraCF = newCF

I’m not great with maths… Any help is appreciated!

for this you will want to use a ray. In the corescripts, this is called the poppercam.

do something like this

while rstep:wait() do
	local distance = (camera.CFrame.p - camera.Focus.p).Magnitude
	local negativeLookVector = camera.CFrame:VectorToWorldSpace(Vector3.new(0, 0, 1))
	local ray = Ray.new(camera.Focus.p, negativeLookVector * distance)
	local partInTheWay, hitPos = workspace:FindPartOnRayWithIgnoreList(ray, {character})
	if partInTheWay and partInTheWay.CanCollide and partInTheWay.Transparency <= 0.1 then -- disable the cancollide and transparency thing if you want, but the popper cam does this
		local newCameraDistanceFromHead = (camera.Focus.p - hitPos).Magnitude
		camera.CFrame = character.Head.CFrame * CFrame.new(0, 0, -newCameraDistanceFromHead)
	end
end