local function a(a)for k,V in pairs(TrackedLimbs)do a[#a+1]=k.Position end end local function k(a)for k=1,MOVE_CASTS,1 do local V,l=Torso.Position,Torso.Velocity local n=(Vector3_new(l.X,0,l.Z)).Magnitude/2 local C=((k-1)*Torso.CFrame.lookVector)*n a[#a+1]=V+C end end local function V(a)local k=Torso.CFrame local V=k.p local l=k-V local n=Character:GetExtentsSize()/2 a[#a+1]=V for k=1,#CORNER_FACTORS,1 do a[#a+1]=V+l*(n*CORNER_FACTORS[k])end end local function l(a)local k=nil if Mode==MODE.CIRCLE1 then k=Torso.CFrame else local a=Camera.CoordinateFrame k=(a-a.p)+Torso.Position end a[#a+1]=k.p for V=0,CIRCLE_CASTS-1,1 do local l=((2*math_pi)/CIRCLE_CASTS)*V local n=3*Vector3_new(math_cos(l),math_sin(l),0)a[#a+1]=k*n end end local function n(V)a(V)k(V)end local function C(a)if childAddedConn then childAddedConn:disconnect()childAddedConn=nil end if childRemovedConn then childRemovedConn:disconnect()childRemovedConn=nil end Character=a TrackedLimbs={}local function k(a)if a:IsA("\066\097\115\101\080\097\114\116")and LIMB_TRACKING_SET[a.Name]then TrackedLimbs[a]=true end end local function V(a)TrackedLimbs[a]=nil end childAddedConn=a.ChildAdded:connect(k)childRemovedConn=a.ChildRemoved:connect(V)for a,V in pairs(Character:GetChildren())do k(V)end end local function T(a)if a=="\067\117\114\114\101\110\116\067\097\109\101\114\097"then local a=workspace.CurrentCamera if a then Camera=a end end end
-----------------------
--| Local Functions |--
-----------------------

local function LimbBehavior(castPoints)
	for limb, _ in pairs(TrackedLimbs) do
		castPoints[#castPoints + 1] = limb.Position
	end
end

local function MoveBehavior(castPoints)
	for i = 1, MOVE_CASTS do
		local position, velocity = Torso.Position, Torso.Velocity
		local horizontalSpeed = Vector3_new(velocity.X, 0, velocity.Z).Magnitude / 2
		local offsetVector = (i - 1) * Torso.CFrame.lookVector * horizontalSpeed
		castPoints[#castPoints + 1] = position + offsetVector
	end
end

local function CornerBehavior(castPoints)
	local cframe = Torso.CFrame
	local centerPoint = cframe.p
	local rotation = cframe - centerPoint
	local halfSize = Character:GetExtentsSize() / 2 --NOTE: Doesn't update w/ limb animations
	castPoints[#castPoints + 1] = centerPoint
	for i = 1, #CORNER_FACTORS do
		castPoints[#castPoints + 1] = centerPoint + (rotation * (halfSize * CORNER_FACTORS[i]))
	end
end

local function CircleBehavior(castPoints)
	local cframe = nil
	if Mode == MODE.CIRCLE1 then
		cframe = Torso.CFrame
	else
		local camCFrame = Camera.CoordinateFrame
		cframe = camCFrame - camCFrame.p + Torso.Position
	end
	castPoints[#castPoints + 1] = cframe.p
	for i = 0, CIRCLE_CASTS - 1 do
		local angle = (2 * math_pi / CIRCLE_CASTS) * i
		local offset = 3 * Vector3_new(math_cos(angle), math_sin(angle), 0)
		castPoints[#castPoints + 1] = cframe * offset
	end
end

local function LimbMoveBehavior(castPoints)
	LimbBehavior(castPoints)
	MoveBehavior(castPoints)
end

local function OnCharacterAdded(character)
	if childAddedConn then
		childAddedConn:disconnect()
		childAddedConn = nil
	end
	if childRemovedConn then
		childRemovedConn:disconnect()
		childRemovedConn = nil
	end

	Character = character

	TrackedLimbs = {}
	local function childAdded(child)
		if child:IsA("BasePart") and LIMB_TRACKING_SET[child.Name] then
			TrackedLimbs[child] = true
		end
	end

	local function childRemoved(child)
		TrackedLimbs[child] = nil
	end

	childAddedConn = character.ChildAdded:connect(childAdded)
	childRemovedConn = character.ChildRemoved:connect(childRemoved)

	for _, child in pairs(Character:GetChildren()) do
		childAdded(child)
	end
end

local function OnWorkspaceChanged(property)
	if property == "CurrentCamera" then
		local newCamera = workspace.CurrentCamera
		if newCamera then
			Camera = newCamera
		end
	end
end
