function Invisicam.Update(g)local q={}Behaviors[Mode](q)local N={}local t={Character}local function P(g)N[g]=true if not SavedHits[g]then SavedHits[g]=g.LocalTransparencyModifier end end for g,q in pairs(q)do repeat local g=CameraCast(q,t)if g then P(g)for g,q in pairs(g:GetChildren())do if q:IsA("\068\101\099\097\108")or q:IsA("\084\101\120\116\117\114\101")then P(q)end end table.insert(t,g)end until not g end for g,q in pairs(SavedHits)do local t=g.LocalTransparencyModifier if N[g]then if t<FADE_TARGET then g.LocalTransparencyModifier=math.min(t+FADE_RATE,FADE_TARGET)end else if t>q then g.LocalTransparencyModifier=math.max(q,t-FADE_RATE)else SavedHits[g]=nil end end end end function Invisicam.SetMode(q,g)AssertTypes(g,"\110\117\109\098\101\114")for q,N in pairs(MODE)do if N==g then Mode=g return end end error("\073\110\118\097\108\105\100 \109\111\100\101 \110\117\109\098\101\114")end function Invisicam.SetCustomBehavior(q,g)AssertTypes(g,"\102\117\110\099\116\105\111\110")Behaviors[MODE.CUSTOM]=g end
-- Update. Called every frame after the camera movement step
function Invisicam:Update()
	-- Make a list of world points to raycast to
	local castPoints = {}
	Behaviors[Mode](castPoints)

	-- Cast to get a list of objects between the camera and the cast points
	local currentHits = {}
	local ignoreList = { Character }
	local function add(hit)
		currentHits[hit] = true
		if not SavedHits[hit] then
			SavedHits[hit] = hit.LocalTransparencyModifier
		end
	end
	for _, worldPoint in pairs(castPoints) do
		repeat
			local hitPart = CameraCast(worldPoint, ignoreList)
			if hitPart then
				add(hitPart)
				for _, child in pairs(hitPart:GetChildren()) do
					if child:IsA("Decal") or child:IsA("Texture") then
						add(child)
					end
				end
				table.insert(ignoreList, hitPart) -- Next ray will go through this part
			end
		until not hitPart
	end

	-- Fade out objects that are in the way, restore those that aren't anymore
	for hit, originalFade in pairs(SavedHits) do
		local currentFade = hit.LocalTransparencyModifier
		if currentHits[hit] then -- Fade
			if currentFade < FADE_TARGET then
				hit.LocalTransparencyModifier = math.min(currentFade + FADE_RATE, FADE_TARGET)
			end
		else -- Restore
			if currentFade > originalFade then
				hit.LocalTransparencyModifier = math.max(originalFade, currentFade - FADE_RATE)
			else
				SavedHits[hit] = nil
			end
		end
	end
end

function Invisicam:SetMode(newMode)
	AssertTypes(newMode, "number")
	for modeName, modeNum in pairs(MODE) do
		if modeNum == newMode then
			Mode = newMode
			return
		end
	end
	error("Invalid mode number")
end

function Invisicam:SetCustomBehavior(func)
	AssertTypes(func, "function")
	Behaviors[MODE.CUSTOM] = func
end
