local function b(b)for S,G in pairs(TrackedLimbs)do if G.Parent then table.insert(b,G.Position)end end end local function S(b)for S=1,MOVE_CASTS,1 do local G,g=Torso.Position,Torso.Velocity local f=(Vector3.new(g.X,0,g.Z)).Magnitude/2 local r=((S-1)*Torso.CFrame.lookVector)*f table.insert(b,G+r)end end local function G(b)local S=Torso.CFrame local G=S.p local g=S-G local f=Character:GetExtentsSize()/2 table.insert(b,G)for S,r in pairs(CORNER_FACTORS)do table.insert(b,G+g*(f*r))end end local function g(b)local S=nil if Mode==MODE.CIRCLE1 then S=Torso.CFrame else local b=Camera.CoordinateFrame S=(b-b.p)+Torso.Position end table.insert(b,S.p)for G=0,CIRCLE_CASTS-1,1 do local g=((2*math.pi)/CIRCLE_CASTS)*G local f=3*Vector3.new(math.cos(g),math.sin(g),0)table.insert(b,S*f)end end local function f(G)b(G)S(G)end local function r(b)Character=b Torso=Character:WaitForChild("\084\111\114\115\111")TrackedLimbs={}for b,S in pairs(Character:GetChildren())do if S:IsA("\066\097\115\101\080\097\114\116")and LIMB_TRACKING_SET[S.Name]then table.insert(TrackedLimbs,S)end end end local function d(b)if b=="\067\117\114\114\101\110\116\067\097\109\101\114\097"then local b=workspace.CurrentCamera if b then Camera=b end end end


local function LimbBehavior(castPoints)
	for _, limb in pairs(TrackedLimbs) do
		if limb.Parent then
			table.insert(castPoints, limb.Position)
		end
	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
		table.insert(castPoints, 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
	table.insert(castPoints, centerPoint)
	for _, factor in pairs(CORNER_FACTORS) do
		table.insert(castPoints, centerPoint + (rotation * (halfSize * factor)))
	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
	table.insert(castPoints, 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)
		table.insert(castPoints, cframe * offset)
	end
end

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

local function OnCharacterAdded(character)
	Character = character
	Torso = Character:WaitForChild('Torso')
	
	TrackedLimbs = {}
	for _, child in pairs(Character:GetChildren()) do
		if child:IsA('BasePart') and LIMB_TRACKING_SET[child.Name] then
			table.insert(TrackedLimbs, child)
		end
	end
end

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