function Invisicam.Update(V)if not Torso then local V=Character:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")if V and V.Torso then Torso=V.Torso else Torso=Character:FindFirstChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116")if not Torso then return end end local L L=Torso.AncestryChanged:connect(function(V,B)if V==Torso and not B then Torso=nil if L and L.Connected then L:Disconnect()L=nil end end end)end local L={}BehaviorFunction(L)local B={}local U={Character}local function A(V)B[V]=true if not SavedHits[V]then SavedHits[V]=V.LocalTransparencyModifier end end local m=Camera:GetPartsObscuringTarget(L,U)for V=1,#m,1 do local L=m[V]A(L)for V,L in pairs(L:GetChildren())do if L:IsA("\068\101\099\097\108")or L:IsA("\084\101\120\116\117\114\101")then A(L)end end end for V,L in pairs(SavedHits)do local U=V.LocalTransparencyModifier if B[V]then if U<FADE_TARGET then V.LocalTransparencyModifier=math_min(U+FADE_RATE,FADE_TARGET)end else if U>L then V.LocalTransparencyModifier=math_max(L,U-FADE_RATE)else SavedHits[V]=nil end end end end function Invisicam.SetMode(L,V)AssertTypes(V,"\110\117\109\098\101\114")for L,B in pairs(MODE)do if B==V then Mode=V BehaviorFunction=Behaviors[Mode]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(L,V)AssertTypes(V,"\102\117\110\099\116\105\111\110")Behaviors[MODE.CUSTOM]=V if Mode==MODE.CUSTOM then BehaviorFunction=V end end
-- Update. Called every frame after the camera movement step
function Invisicam:Update()
	-- Make sure we still have a Torso
	if not Torso then
		local humanoid = Character:FindFirstChildOfClass("Humanoid")
		if humanoid and humanoid.Torso then
			Torso = humanoid.Torso
		else
			-- Not set up with Humanoid? Try and see if there's one in the Character at all:
			Torso = Character:FindFirstChild("HumanoidRootPart")
			if not Torso then
				-- Bail out, since we're relying on Torso existing
				return
			end
		end
		local ancestryChangedConn
		ancestryChangedConn = Torso.AncestryChanged:connect(function(child, parent)
			if child == Torso and not parent then
				Torso = nil
				if ancestryChangedConn and ancestryChangedConn.Connected then
					ancestryChangedConn:Disconnect()
					ancestryChangedConn = nil
				end
			end
		end)
	end

	-- Make a list of world points to raycast to
	local castPoints = {}
	BehaviorFunction(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

	local hitParts = Camera:GetPartsObscuringTarget(castPoints, ignoreList)
	for i = 1, #hitParts do
		local hitPart = hitParts[i]
		add(hitPart)
		for _, child in pairs(hitPart:GetChildren()) do
			if child:IsA("Decal") or child:IsA("Texture") then
				add(child)
			end
		end
	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
			BehaviorFunction = Behaviors[Mode]
			return
		end
	end
	error("Invalid mode number")
end

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