Hey so i made a custom 3rd person camera for my game, and I made a simple raycast from the character’s head to the Camera’s position to stop the camera clipping through walls. This works but sometimes when you aim down sights for example it clips through the wall. I dont know how to fix this and im not sure if i overlooked something simple.
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