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!