local function q()wait()Forward=UIS:IsKeyDown("\087")or UIS:IsKeyDown("\085\112")Backward=UIS:IsKeyDown("\083")or UIS:IsKeyDown("\068\111\119\110")local q=UIS:IsKeyDown("\068")local U=UIS:IsKeyDown("\065")local y=Forward and not Backward local M=not Forward and Backward local A=q and not U local g=not q and U if Forward or Backward or q or U then Walking,Idling=true,false if not Running and not Aimed then spreadMotion="\077\111\118\105\110\103"baseSpread=S.spreadSettings[spreadZoom][spreadStance][spreadMotion]end elseif not(Forward and(Backward and(q and U)))then Walking,Idling=false,true if not Aimed then spreadMotion="\073\100\108\105\110\103"baseSpread=S.spreadSettings[spreadZoom][spreadStance][spreadMotion]end end local a=((y or M)and A)and 2.5 or((y or M)and g)and-2.5 or(not(y and M)and A)and 5 or(not(y and M)and g)and-5 or 0 local F=(y and not(A or g))and 0 or(y and A)and RAD(-45)or(not(y or M)and A)and RAD(-90)or(M and A)and RAD(-135)or(M and not(A or g))and(moveAng<0 and RAD(-180)or RAD(180))or(M and g)and RAD(135)or(not(y or M)and g)and RAD(90)or(y and g)and RAD(45)or 0 local J=math.random(-1000000000.0,1000000000.0)animCode=J local v=armTilt local d=ABS(moveAng)==RAD(180)and(F>0 and RAD(180)or RAD(-180))or moveAng local D=v==a and 2.1428571428571 or 1.5/((.35*ABS(v-a))/5)local O=0 while true do RS.RenderStepped:wait()local q=O+D O=q>90 and 90 or q if animCode~=J then break end armTilt=numLerp(v,a,Sine(O))moveAng=numLerp(d,F,Sine(O))if O==90 then break end end end M2.KeyDown:connect(q)M2.KeyUp:connect(q)q()


local function updateAnimVars()
	wait()
	Forward = (UIS:IsKeyDown("W") or UIS:IsKeyDown("Up"))
	Backward = (UIS:IsKeyDown("S") or UIS:IsKeyDown("Down"))
	local Right = UIS:IsKeyDown("D")
	local Left = UIS:IsKeyDown("A")
	
	local walkingForward = (Forward and (not Backward))
	local walkingBackward = ((not Forward) and Backward)
	local walkingRight = (Right and (not Left))
	local walkingLeft = ((not Right) and Left)
	
	if (Forward or Backward or Right or Left) then
		Walking, Idling = true, false
		if (not Running) and (not Aimed) then
			spreadMotion = "Moving"
			baseSpread = S.spreadSettings[spreadZoom][spreadStance][spreadMotion]
		end
	elseif (not (Forward and Backward and Right and Left)) then
		Walking, Idling = false, true
		if (not Aimed) then
			spreadMotion = "Idling"
			baseSpread = S.spreadSettings[spreadZoom][spreadStance][spreadMotion]
		end
	end
	
	local newArmTilt = (
		((walkingForward or walkingBackward) and walkingRight) and 2.5 or
		((walkingForward or walkingBackward) and walkingLeft) and -2.5 or
		((not (walkingForward and walkingBackward)) and walkingRight) and 5 or
		((not (walkingForward and walkingBackward)) and walkingLeft) and -5 or 0
	)
	local newMoveAng = (
		(walkingForward and (not (walkingRight or walkingLeft))) and 0 or
		(walkingForward and walkingRight) and RAD(-45) or
		((not (walkingForward or walkingBackward)) and walkingRight) and RAD(-90) or
		(walkingBackward and walkingRight) and RAD(-135) or
		(walkingBackward and (not (walkingRight or walkingLeft))) and (moveAng < 0 and RAD(-180) or RAD(180)) or
		(walkingBackward and walkingLeft) and RAD(135) or
		((not (walkingForward or walkingBackward)) and walkingLeft) and RAD(90) or
		(walkingForward and walkingLeft) and RAD(45) or 0
	)
	
	local newAnimCode = math.random(-1e9, 1e9)
	animCode = newAnimCode
	local startTilt = armTilt
	local startAng = (ABS(moveAng) == RAD(180)) and (newMoveAng > 0 and RAD(180) or RAD(-180)) or moveAng
	local Increment = (startTilt == newArmTilt and 1.5 / 0.7 or 1.5 / (0.35 * ABS(startTilt - newArmTilt) / 5))
	local X = 0
	while true do
		RS.RenderStepped:wait()
		local newX = X + Increment
		X = (newX > 90 and 90 or newX)
		if animCode ~= newAnimCode then break end
		armTilt = numLerp(startTilt, newArmTilt, Sine(X))
		moveAng = numLerp(startAng, newMoveAng, Sine(X))
		if X == 90 then break end
	end
end

M2.KeyDown:connect(updateAnimVars)
M2.KeyUp:connect(updateAnimVars)
updateAnimVars()
