module.getQueueFunction=function(L)local c=L:WaitForChild("\072\117\109\097\110\111\105\100")local U=L:WaitForChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116")local M=L:WaitForChild("\085\112\112\101\114\084\111\114\115\111")local r=L:WaitForChild("\076\111\119\101\114\084\111\114\115\111")local W=M:WaitForChild("\087\097\105\115\116")local A=r:WaitForChild("\082\111\111\116")local q=A.C0 local t=A.C1 local o=W.C1 local N=L:WaitForChild("\082\105\103\104\116\085\112\112\101\114\076\101\103")local O=L:WaitForChild("\082\105\103\104\116\076\111\119\101\114\076\101\103")local z=L:WaitForChild("\076\101\102\116\085\112\112\101\114\076\101\103")local R=L:WaitForChild("\076\101\102\116\076\111\119\101\114\076\101\103")local d=N:WaitForChild("\082\105\103\104\116\072\105\112")local K=O:WaitForChild("\082\105\103\104\116\075\110\101\101")local x=z:WaitForChild("\076\101\102\116\072\105\112")local i=R:WaitForChild("\076\101\102\116\075\110\101\101")local h=d.C0 local D=K.C0 local j=x.C0 local B=i.C0 local Z=V3(1,0,1)local S=2.3 local F=14 local m,C=0,math.pi local T=CF(0,0,-S/2)local y=RaycastParams.new()y.FilterDescendantsInstances={L}y.IgnoreWater=true y.FilterType=Enum.RaycastFilterType.Blacklist return function(L)local M=math.min(L*10,1)local A=r.CFrame local q=U.CFrame local t=U.Velocity local N,O local z=c:GetState()==Enum.HumanoidStateType.Climbing if z then N=t O=N.Magnitude Z=q.lookVector else N=t*x_and_y O=N.Magnitude if O>.1 then Z=Z:Lerp(N.unit,M)end end local R=O/16 local S=(R*L)*F C=(C+S)%tau m=(m+S)%tau if O>.1 then local L=A:vectorToObjectSpace(N)local c=L*.2 local U=L.X/N.Magnitude do W.C1=W.C1:Lerp(o*(ANGLES(math.rad(c.Z),.1*math.cos(C)-2*math.rad(c.X),math.rad(-c.X))):inverse(),M)end do local L=(q*rhipcf).p local c=(q*rhipcf2).p local U=((CF(c,c+Z)*ANGLES(-C,0,0))*T).p local M=U-L local r=workspace:Raycast(L,M.unit*(M.magnitude+.5),y)local W=r and r.Position or L+M.unit*(M.magnitude+.5)local t,o,N=solveLegIK(A*h,W,.55,1.15)d.C0=d.C0:Lerp(A:toObjectSpace(t)*ANGLES(o,0,0),.25)K.C0=K.C0:Lerp(D*ANGLES(N,0,0),.25)end do local L=(q*lhipcf).p local c=(q*lhipcf2).p local U=((CF(c,c+Z)*ANGLES(-m,0,0))*T).p local M=U-L local r=workspace:Raycast(L,M.unit*(M.magnitude+.5),y)local W=r and r.Position or L+M.unit*(M.magnitude+.5)local t,o,N=solveLegIK(A*j,W,.55,1.15)x.C0=x.C0:Lerp(A:toObjectSpace(t)*ANGLES(o,0,0),.25)i.C0=i.C0:Lerp(B*ANGLES(N,0,0),.25)end else W.C1=W.C1:Lerp(o,M)do local L=q*rhipcf local c=L.p local U=(L*rIdle).p local M=U-c local r=workspace:Raycast(c,M.unit*(M.magnitude+.5),y)local W=r and r.Position or c+M.unit*(M.magnitude+.5)local t,o,N=solveLegIK(A*h,W,.55,1.15)d.C0=d.C0:Lerp(A:toObjectSpace(t)*ANGLES(o,0,0),.25)K.C0=K.C0:Lerp(D*ANGLES(N,0,0),.25)end do local L=q*lhipcf local c=L.p local U=(L*lIdle).p local M=U-c local r=workspace:Raycast(c,M.unit*(M.magnitude+.5),y)local W=r and r.Position or c+M.unit*(M.magnitude+.5)local t,o,N=solveLegIK(A*j,W,.55,1.15)x.C0=x.C0:Lerp(A:toObjectSpace(t)*ANGLES(o,0,0),.25)i.C0=i.C0:Lerp(B*ANGLES(N,0,0),.25)end end end end return module


module.getQueueFunction = function(character)
	-- Get all the base parts and values needed to further calculate everything
	local humanoid		=character:WaitForChild("Humanoid")
	local rootpart		=character:WaitForChild("HumanoidRootPart")
	local uppertorso	=character:WaitForChild("UpperTorso")
	local lowertorso	=character:WaitForChild("LowerTorso")
	local waistjoint	=uppertorso:WaitForChild("Waist")
	local rootjoint		=lowertorso:WaitForChild("Root")
	local root0			=rootjoint.C0
	local root1			=rootjoint.C1
	local waist1		=waistjoint.C1
	
	local rightupperleg	=character:WaitForChild("RightUpperLeg")
	local rightlowerleg	=character:WaitForChild("RightLowerLeg")
	local leftupperleg	=character:WaitForChild("LeftUpperLeg")
	local leftlowerleg	=character:WaitForChild("LeftLowerLeg")
	local righthip		=rightupperleg:WaitForChild("RightHip")
	local rightknee		=rightlowerleg:WaitForChild("RightKnee")
	local lefthip		=leftupperleg:WaitForChild("LeftHip")
	local leftknee		=leftlowerleg:WaitForChild("LeftKnee")
	local righthip0		=righthip.C0
	local rightknee0	=rightknee.C0
	local lefthip0		=lefthip.C0
	local leftknee0		=leftknee.C0
	--
	
	local direction		= V3(1,0,1) -- This will be changed
	local stride		= 2.3 -- Changes how far the legs move
	local cycleSpeed	= 14 -- How fast the leg-movement cycle is. Change this to suit your needs!
	local left,right	= 0,math.pi -- Initial rotations
	
	local strideCF		= CF(0,0,-stride/2) -- Turn that stride number into a CFrame we can use
	
	local raycastParams = RaycastParams.new() -- Used for raycasting
	raycastParams.FilterDescendantsInstances = {character}
	raycastParams.IgnoreWater = true
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	
	--
	
	return function(dt) -- dt, or delta, is the amount of time passed between render frames. 1/dt = frames per second
		local dt10		=math.min(dt*10,1) -- Normalize dt for our needs
		
		local lowercf	=lowertorso.CFrame -- Our position
		local rootcf	=rootpart.CFrame -- Another position
		local rootvel0	=rootpart.Velocity -- Our movement velocity
		local rootvel,rootvelm
		local climbing	=humanoid:GetState()==Enum.HumanoidStateType.Climbing -- Are we climbing?
		
		--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--
		--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--
		
		if climbing then -- Don't animate if we are climbing, it looks weird
			rootvel		=rootvel0
			rootvelm	=rootvel.Magnitude
			direction	=rootcf.lookVector
		else
			rootvel		=rootvel0*x_and_y
			rootvelm	=rootvel.Magnitude
			
			if rootvelm>0.1 then
				direction	=direction:Lerp(rootvel.unit, dt10)
			end
		end
		
		--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--
		--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--
		
		local up		=rootvelm/16
		local cycle		=up*dt*cycleSpeed
		right			=(right+cycle)%tau
		left			=(left+cycle)%tau
		
		--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--
		--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--
		
		if rootvelm>0.1 then --// When moving
			-- Relative Velocity
			local relv0		=lowercf:vectorToObjectSpace(rootvel)
			local relv1		=relv0*0.2
			local relvx		=relv0.X/rootvel.Magnitude
			
			do -- Upper Torso
				waistjoint.C1	=waistjoint.C1:Lerp(waist1*ANGLES(math.rad(relv1.Z),0.1*math.cos(right)-2*math.rad(relv1.X),math.rad(-relv1.X)):inverse(),dt10)		
			end
			
			do -- Right Leg
				local hip			=(rootcf*rhipcf).p
				local ground		=(rootcf*rhipcf2).p
				local desiredPos	=(CF(ground, ground+direction)*ANGLES(-right, 0, 0)*strideCF).p
				local offset		=(desiredPos-hip)
				local raycastResult = workspace:Raycast(hip,offset.unit*(offset.magnitude+0.5),raycastParams)
				local footPos = raycastResult and raycastResult.Position or (hip + offset.unit*(offset.magnitude+0.5))
				
				local plane,th1,th2		=solveLegIK(lowercf*righthip0,footPos, 0.55,1.15) -- 0.55,1.15
				righthip.C0				=righthip.C0:Lerp(lowercf:toObjectSpace(plane)*ANGLES(th1,0,0),0.25)
				rightknee.C0			=rightknee.C0:Lerp(rightknee0*ANGLES(th2,0,0),0.25)
			end
			
			do-- Left Leg
				local hip			=(rootcf*lhipcf).p
				local ground 		=(rootcf*lhipcf2).p
				local desiredPos	=(CF(ground, ground+direction)*ANGLES(-left, 0, 0)*strideCF).p
				local offset		=(desiredPos-hip)
				local raycastResult = workspace:Raycast(hip,offset.unit*(offset.magnitude+0.5),raycastParams)
				local footPos = raycastResult and raycastResult.Position or (hip + offset.unit*(offset.magnitude+0.5))
				
				local plane,th1,th2		=solveLegIK(lowercf*lefthip0,footPos, 0.55,1.15)
				lefthip.C0				=lefthip.C0:Lerp(lowercf:toObjectSpace(plane)*ANGLES(th1,0,0),0.25)
				leftknee.C0				=leftknee.C0:Lerp(leftknee0*ANGLES(th2,0,0),0.25)
			end
			
			--|||||||||||--
			--|||||||||||--
			
		else --// When not moving
			-- Upper Torso
			waistjoint.C1	=waistjoint.C1:Lerp(waist1, dt10)
			
			do -- Right Leg
				local hipcf			=(rootcf*rhipcf)
				local hip			=hipcf.p
				local desiredPos	=(hipcf*rIdle).p
				local offset		=(desiredPos-hip)
				local raycastResult = workspace:Raycast(hip,offset.unit*(offset.magnitude+0.5),raycastParams)
				local footPos = raycastResult and raycastResult.Position or (hip + offset.unit*(offset.magnitude+0.5))
				
				local plane,th1,th2		=solveLegIK(lowercf*righthip0,footPos, 0.55,1.15)
				righthip.C0				=righthip.C0:Lerp(lowercf:toObjectSpace(plane)*ANGLES(th1,0,0),0.25)
				rightknee.C0			=rightknee.C0:Lerp(rightknee0*ANGLES(th2,0,0),0.25)
			end
			
			do -- Left Leg
				local hipcf			=(rootcf*lhipcf)
				local hip			=hipcf.p
				local desiredPos	=(hipcf*lIdle).p
				local offset		=(desiredPos-hip)
				local raycastResult = workspace:Raycast(hip,offset.unit*(offset.magnitude+0.5),raycastParams)
				local footPos = raycastResult and raycastResult.Position or (hip + offset.unit*(offset.magnitude+0.5))
				
				local plane,th1,th2		=solveLegIK(lowercf*lefthip0,footPos, 0.55,1.15)
				lefthip.C0				=lefthip.C0:Lerp(lowercf:toObjectSpace(plane)*ANGLES(th1,0,0),0.25)
				leftknee.C0				=leftknee.C0:Lerp(leftknee0*ANGLES(th2,0,0),0.25)
			end
			
			--|||||||||||--
			--|||||||||||--
		end
	end
	
	--
end

return module
