function PopperCam.Update(U)if PopperEnabled then local U=Camera.Focus.p local c=Camera.CoordinateFrame local t=c.p+c.lookVector*NEAR_CLIP_PLANE_OFFSET local d=Camera.ViewportSize local u={}for U,c in pairs(PlayerCharacters)do table.insert(u,c)end for U,c in pairs(VehicleParts)do table.insert(u,c)end local j=0 for c,a in pairs(CAST_SCREEN_SCALES)do local w=ScreenToWorld(d*a,d,NEAR_CLIP_PLANE_OFFSET)local q=U+(w-t)local R,T=PiercingCast(q,w,u)local o=(T-w).Magnitude if o>j then j=o end end local a=(c.p-U).Magnitude if math.abs(a-LastZoomLevel)>.001 then LastPopAmount=0 end local w=math.max(j,LastPopAmount)if w>0 then Camera.CoordinateFrame=c+c.lookVector*w LastPopAmount=math.max(0,w-POP_RESTORE_RATE)end LastZoomLevel=a end end


function PopperCam:Update()
	if PopperEnabled then
		-- First, prep some intermediate vars
		local focusPoint = Camera.Focus.p
		local cameraCFrame = Camera.CoordinateFrame
		local cameraFrontPoint = cameraCFrame.p + (cameraCFrame.lookVector * NEAR_CLIP_PLANE_OFFSET)
		local screenSize = Camera.ViewportSize
		local ignoreList = {}
		for _, character in pairs(PlayerCharacters) do
			table.insert(ignoreList, character)
		end
		for _, basePart in pairs(VehicleParts) do
			table.insert(ignoreList, basePart)
		end
		
		-- Cast rays at the near clip plane, from corresponding points near the focus point,
		-- and find the direct line that is the most cut off
		local largest = 0
		for _, screenScale in pairs(CAST_SCREEN_SCALES) do
			local clipWorldPoint = ScreenToWorld(screenSize * screenScale, screenSize, NEAR_CLIP_PLANE_OFFSET)
			local rayStartPoint = focusPoint + (clipWorldPoint - cameraFrontPoint)
			local _, hitPoint = PiercingCast(rayStartPoint, clipWorldPoint, ignoreList)
			local cutoffAmount = (hitPoint - clipWorldPoint).Magnitude
			if cutoffAmount > largest then
				largest = cutoffAmount
			end
		end
		
		-- Then check if the player zoomed since the last frame,
		-- and if so, reset our pop history so we stop tweening
		local zoomLevel = (cameraCFrame.p - focusPoint).Magnitude
		if math.abs(zoomLevel - LastZoomLevel) > 0.001 then
			LastPopAmount = 0
		end
		
		-- Finally, zoom the camera in (pop) by that most-cut-off amount, or the last pop amount if that's more
		local popAmount = math.max(largest, LastPopAmount)
		if popAmount > 0 then
			Camera.CoordinateFrame = cameraCFrame + (cameraCFrame.lookVector * popAmount)
			LastPopAmount = math.max(0, popAmount - POP_RESTORE_RATE) -- Shrink it for the next frame
		end
		
		LastZoomLevel = zoomLevel
	end
end
