In the attached image the section with the red squiggle is actually supposed to be a part, hence my camera system is clipping slightly through the part.
camera.Focus is set to the player’s head.
The CFrame I calculate the GetLargestCutOffDistance from is the camera CFrame that it would be with no obstructions.
If the distance returned is greater than zero I move the camera the returned distance towards the camera focus.
Hence I am confused as to why this is not working!
Edit: I should say that it is “working” in that it moves the camera in the correct direction and mostly the correct distance however the issue is why it isn’t moving it the “full” distance needed to prevent this clipping.
Code:
local function UpdateCamera(mousedelta)
local crX = currentrotation.X
local crY = currentrotation.Y
if player.Character ~= nil then
crX = crX - math.rad(mousedelta.X)*sensitivity
crY = crY - math.rad(mousedelta.Y)*sensitivity
crX = crX % (2*math.pi)
if crY > math.rad(70) then
crY = math.rad(70)
elseif crY < math.rad(-70) then
crY = math.rad(-70)
end
currentrotation = Vector2.new(crX,crY)
local goalCFrame = CFrame.new(player.Character.HumanoidRootPart.CFrame.Position)
* CFrame.Angles(0,currentrotation.X + recoil.X,0) -- possibly consider moving these recoil factors into the crX and crY system
* CFrame.Angles(currentrotation.Y + recoil.Y,0,0)
*CFrame.new(0,0,zoom)
* CFrame.new(2.5,2.5,0) -- offset
cam.Focus = player.Character.HumanoidRootPart.CFrame * CFrame.new(0,2,0)
cam.CFrame = goalCFrame
local popdistance = cam:GetLargestCutoffDistance({player.Character}) -- ignore list is simply the character for now
cam.CFrame = cam.CFrame - ((popdistance) * (cam.CFrame.Position - cam.Focus.Position).unit)
end
end