function moveFreeFall()RightShoulder.MaxVelocity=jumpMaxLimbVelocity LeftShoulder.MaxVelocity=jumpMaxLimbVelocity RightShoulder:SetDesiredAngle(3.14)LeftShoulder:SetDesiredAngle(-3.14)RightHip:SetDesiredAngle(0)LeftHip:SetDesiredAngle(0)end function moveSit()RightShoulder.MaxVelocity=.15 LeftShoulder.MaxVelocity=.15 RightShoulder:SetDesiredAngle(1.57)LeftShoulder:SetDesiredAngle(-1.57)RightHip:SetDesiredAngle(1.57)LeftHip:SetDesiredAngle(-1.57)end function getTool()for t,i in ipairs(Figure:GetChildren())do if i.className=="\084\111\111\108"then return i end end return nil end function getToolAnim(t)for t,i in ipairs(t:GetChildren())do if i.Name=="\116\111\111\108\097\110\105\109"and i.className=="\083\116\114\105\110\103\086\097\108\117\101"then return i end end return nil end function animateTool()if toolAnim=="\078\111\110\101"then RightShoulder:SetDesiredAngle(1.57)return end if toolAnim=="\083\108\097\115\104"then RightShoulder.MaxVelocity=.5 RightShoulder:SetDesiredAngle(0)return end if toolAnim=="\076\117\110\103\101"then RightShoulder.MaxVelocity=.5 LeftShoulder.MaxVelocity=.5 RightHip.MaxVelocity=.5 LeftHip.MaxVelocity=.5 RightShoulder:SetDesiredAngle(1.57)LeftShoulder:SetDesiredAngle(1.0)RightHip:SetDesiredAngle(1.57)LeftHip:SetDesiredAngle(1.0)return end end function move(t)local i local o if pose=="\074\117\109\112\105\110\103"then moveJump()return end if pose=="\070\114\101\101\070\097\108\108"then moveFreeFall()return end if pose=="\083\101\097\116\101\100"then moveSit()return end local x=0 if pose=="\082\117\110\110\105\110\103"then if RightShoulder.CurrentAngle>1.5 or RightShoulder.CurrentAngle<-1.5 then RightShoulder.MaxVelocity=jumpMaxLimbVelocity else RightShoulder.MaxVelocity=.15 end if LeftShoulder.CurrentAngle>1.5 or LeftShoulder.CurrentAngle<-1.5 then LeftShoulder.MaxVelocity=jumpMaxLimbVelocity else LeftShoulder.MaxVelocity=.15 end i=1 o=9 elseif pose=="\067\108\105\109\098\105\110\103"then RightShoulder.MaxVelocity=.5 LeftShoulder.MaxVelocity=.5 i=1 o=9 x=3.14 else i=.1 o=1 end desiredAngle=i*math.sin(t*o)RightShoulder:SetDesiredAngle(desiredAngle+x)LeftShoulder:SetDesiredAngle(desiredAngle-x)RightHip:SetDesiredAngle(-desiredAngle)LeftHip:SetDesiredAngle(-desiredAngle)local P=getTool()if P then animStringValueObject=getToolAnim(P)if animStringValueObject then toolAnim=animStringValueObject.Value animStringValueObject.Parent=nil toolAnimTime=t+.3 end if t>toolAnimTime then toolAnimTime=0 toolAnim="\078\111\110\101"end animateTool()else toolAnim="\078\111\110\101"toolAnimTime=0 end end


function moveFreeFall()
	RightShoulder.MaxVelocity = jumpMaxLimbVelocity
	LeftShoulder.MaxVelocity = jumpMaxLimbVelocity
	RightShoulder:SetDesiredAngle(3.14)
	LeftShoulder:SetDesiredAngle(-3.14)
	RightHip:SetDesiredAngle(0)
	LeftHip:SetDesiredAngle(0)
end

function moveSit()
	RightShoulder.MaxVelocity = 0.15
	LeftShoulder.MaxVelocity = 0.15
	RightShoulder:SetDesiredAngle(3.14 /2)
	LeftShoulder:SetDesiredAngle(-3.14 /2)
	RightHip:SetDesiredAngle(3.14 /2)
	LeftHip:SetDesiredAngle(-3.14 /2)
end

function getTool()	
	for _, kid in ipairs(Figure:GetChildren()) do
		if kid.className == "Tool" then return kid end
	end
	return nil
end

function getToolAnim(tool)
	for _, c in ipairs(tool:GetChildren()) do
		if c.Name == "toolanim" and c.className == "StringValue" then
			return c
		end
	end
	return nil
end

function animateTool()
	
	if (toolAnim == "None") then
		RightShoulder:SetDesiredAngle(1.57)
		return
	end

	if (toolAnim == "Slash") then
		RightShoulder.MaxVelocity = 0.5
		RightShoulder:SetDesiredAngle(0)
		return
	end

	if (toolAnim == "Lunge") then
		RightShoulder.MaxVelocity = 0.5
		LeftShoulder.MaxVelocity = 0.5
		RightHip.MaxVelocity = 0.5
		LeftHip.MaxVelocity = 0.5
		RightShoulder:SetDesiredAngle(1.57)
		LeftShoulder:SetDesiredAngle(1.0)
		RightHip:SetDesiredAngle(1.57)
		LeftHip:SetDesiredAngle(1.0)
		return
	end
end

function move(time)
	local amplitude
	local frequency
  
	if (pose == "Jumping") then
		moveJump()
		return
	end

	if (pose == "FreeFall") then
		moveFreeFall()
		return
	end
 
	if (pose == "Seated") then
		moveSit()
		return
	end

	local climbFudge = 0
	
	if (pose == "Running") then
    if (RightShoulder.CurrentAngle > 1.5 or RightShoulder.CurrentAngle < -1.5) then
			RightShoulder.MaxVelocity = jumpMaxLimbVelocity
		else			
			RightShoulder.MaxVelocity = 0.15
		end
		if (LeftShoulder.CurrentAngle > 1.5 or LeftShoulder.CurrentAngle < -1.5) then
			LeftShoulder.MaxVelocity = jumpMaxLimbVelocity
		else			
			LeftShoulder.MaxVelocity = 0.15
		end
		amplitude = 1
		frequency = 9
	elseif (pose == "Climbing") then
		RightShoulder.MaxVelocity = 0.5 
		LeftShoulder.MaxVelocity = 0.5
		amplitude = 1
		frequency = 9
		climbFudge = 3.14
	else
		amplitude = 0.1
		frequency = 1
	end

	desiredAngle = amplitude * math.sin(time*frequency)

	RightShoulder:SetDesiredAngle(desiredAngle + climbFudge)
	LeftShoulder:SetDesiredAngle(desiredAngle - climbFudge)
	RightHip:SetDesiredAngle(-desiredAngle)
	LeftHip:SetDesiredAngle(-desiredAngle)


	local tool = getTool()

	if tool then
	
		animStringValueObject = getToolAnim(tool)

		if animStringValueObject then
			toolAnim = animStringValueObject.Value
			-- message recieved, delete StringValue
			animStringValueObject.Parent = nil
			toolAnimTime = time + .3
		end

		if time > toolAnimTime then
			toolAnimTime = 0
			toolAnim = "None"
		end

		animateTool()

		
	else
		toolAnim = "None"
		toolAnimTime = 0
	end
end

