-------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------



function OnRunning(Speed)
	if Speed > 0.01 then
		PlayAnimation("Walk", 0.1, Humanoid)
		Pose = "Running"
	else
		PlayAnimation("Idle", 0.1, Humanoid)
		Pose = "Standing"
	end
end

function OnDied()
	Pose = "Dead"
end

function OnJumping()
	PlayAnimation("Jump", 0.1, Humanoid)
	JumpAnimTime = JumpAnimDuration
	Pose = "Jumping"
end

function OnClimbing(Speed)
	PlayAnimation("Climb", 0.1, Humanoid)
	SetAnimationSpeed(Speed / 12)
	Pose = "Climbing"
end

function OnGettingUp()
	Pose = "GettingUp"
end

function OnFreeFall()
	if JumpAnimTime <= 0 then
		PlayAnimation("Fall", FallTransitionTime, Humanoid)
	end
	Pose = "FreeFall"
end

function OnFallingDown()
	Pose = "FallingDown"
end

function OnSeated()
	Pose = "Seated"
end

function OnPlatformStanding()
	Pose = "PlatformStanding"
end

function OnSwimming(Speed)
	if Speed > 0 then
		Pose = "Running"
	else
		Pose = "Standing"
	end
end

function GetTool()	
	for i, Tool in pairs(Figure:GetChildren()) do
		if Tool:IsA("Tool") then
			return Tool
		end
	end
	return nil
end

function GetToolAnim(Tool)
	for i, Anim in pairs(Tool:GetChildren()) do
		if string.lower(Anim.Name) == string.lower("ToolAnim") and Anim:IsA("StringValue") then
			return Anim
		end
	end
	return nil
end

function AnimateTool()
	
	if ToolAnim == "None" then
		PlayToolAnimation("ToolNone", ToolTransitionTime, Humanoid)
		return
	end

	if ToolAnim == "Slash" then
		PlayToolAnimation("ToolSlash", 0, Humanoid)
		return
	end

	if ToolAnim == "Lunge" then
		PlayToolAnimation("ToolLunge", 0, Humanoid)
		return
	end
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)
	RightHip:SetDesiredAngle(1)
	RightHip.CurrentAngle = RightHip.DesiredAngle
	LeftHip:SetDesiredAngle(-1)
	LeftHip.CurrentAngle = LeftHip.DesiredAngle
end

local LastTick = 0

function Move(Time)
	local Amplitude = 1
	local Frequency = 1
  	local DeltaTime = (Time - LastTick)
  	LastTick = Time

	local ClimbFudge = 0
	local SetAngles = false

  	if JumpAnimTime > 0 then
  		JumpAnimTime = (JumpAnimTime - DeltaTime)
  	end

	if Pose == "FreeFall" and JumpAnimTime <= 0 then
		PlayAnimation("Fall", FallTransitionTime, Humanoid)
	elseif Pose == "Seated" then
		StopAllAnimations()
		MoveSit()
		return
	elseif Pose == "Running" then
		PlayAnimation("Walk", 0.1, Humanoid)
	elseif Pose == "Dead" or Pose == "GettingUp" or Pose == "FallingDown" or Pose == "Seated" or Pose == "PlatformStanding" then