function onFall(k)spawn(function()local a=math.max(math.min(k/Humanoid.JumpPower,1),0)local P=jumpAnim.Pos local z=jumpAnim.Rot local B=(.04*S.fallSettings.fallMultiplier)*a local M=(RAD(4)*S.fallSettings.fallMultiplier)*a local R=tick()while true do RS.Heartbeat:wait()local k=math.min((tick()-R)/.15,1)*90 if onGround then break end jumpAnim.Pos=numLerp(P,B,Sine(k))jumpAnim.Rot=numLerp(z,M,Sine(k))if k==90 then break end end P=B z=M B=-0.08*S.fallSettings.fallMultiplier M=-RAD(8)*S.fallSettings.fallMultiplier local Q=1 while true do local k=RS.Heartbeat:wait()Q=Q+(k*60)/Q local a=(Q-1)/15 if onGround then break end jumpAnim.Pos=numLerp(P,B,a)jumpAnim.Rot=numLerp(z,M,a)end end)end function onLand(k)spawn(function()local a=math.min(k,S.fallSettings.maxDist)*.66666666666667 local P=jumpAnim.Pos local z=jumpAnim.Rot local B=((a/100)*S.fallSettings.landMultiplier)*(runReady and 1 or 2)local M=(RAD(a)*S.fallSettings.landMultiplier)*(runReady and 1 or 2)local R=tick()while true do RS.Heartbeat:wait()local k=math.min((tick()-R)/.2,1)if not onGround then break end jumpAnim.Pos=numLerp(P,B,k)jumpAnim.Rot=numLerp(z,M,k)if k==1 then break end end R=tick()while true do RS.Heartbeat:wait()local k=math.min((tick()-R)/.3,1)*90 if not onGround then break end jumpAnim.Pos=numLerp(B,0,Sine(k))jumpAnim.Rot=numLerp(M,0,Sine(k))if k==90 then break end end end)end function onHumanoidStateChanged(k,a)if a==Enum.HumanoidStateType.Freefall then onGround=false if S.fallAnimation then onFall(HRP.Velocity.Y)while HRP.Velocity.Y>0 do RS.RenderStepped:wait()end startFallHeight=HRP.Position.Y end elseif k==Enum.HumanoidStateType.Freefall then onGround=true if S.fallAnimation then local k=startFallHeight-HRP.Position.Y onLand(k)end end end


function onFall(initialVelocity)
	spawn(function()
		local velocityAlpha = math.max(math.min(initialVelocity / Humanoid.JumpPower, 1), 0)
		local startJumpPos = jumpAnim.Pos
		local startJumpRot = jumpAnim.Rot
		local endJumpPos = 0.04 * S.fallSettings.fallMultiplier * velocityAlpha
		local endJumpRot = RAD(4) * S.fallSettings.fallMultiplier * velocityAlpha
		local t0 = tick()
		while true do
			RS.Heartbeat:wait()
			local Alpha = math.min((tick() - t0) / 0.15, 1) * 90
			if onGround then break end
			jumpAnim.Pos = numLerp(startJumpPos, endJumpPos, Sine(Alpha))
			jumpAnim.Rot = numLerp(startJumpRot, endJumpRot, Sine(Alpha))
			if Alpha == 90 then break end
		end
		startJumpPos = endJumpPos
		startJumpRot = endJumpRot
		endJumpPos = -0.08 * S.fallSettings.fallMultiplier
		endJumpRot = -RAD(8) * S.fallSettings.fallMultiplier
		local X = 1
		while true do
			local dt = RS.Heartbeat:wait()
			X = X + (dt * 60) / X
			local Alpha = (X - 1) / 15
			if onGround then break end
			jumpAnim.Pos = numLerp(startJumpPos, endJumpPos, Alpha)
			jumpAnim.Rot = numLerp(startJumpRot, endJumpRot, Alpha)
		end
	end)
end

function onLand(fallDist)
	spawn(function()
		local animAlpha = math.min(fallDist, S.fallSettings.maxDist) * (2 / 3)
		local startJumpPos = jumpAnim.Pos
		local startJumpRot = jumpAnim.Rot
		local endJumpPos = animAlpha / 100 * S.fallSettings.landMultiplier * (runReady and 1 or 2)
		local endJumpRot = RAD(animAlpha) * S.fallSettings.landMultiplier * (runReady and 1 or 2)
		local t0 = tick()
		while true do
			RS.Heartbeat:wait()
			local Alpha = math.min((tick() - t0) / 0.2, 1)
			if (not onGround) then break end
			jumpAnim.Pos = numLerp(startJumpPos, endJumpPos, Alpha)
			jumpAnim.Rot = numLerp(startJumpRot, endJumpRot, Alpha)
			if Alpha == 1 then break end
		end
		t0 = tick()
		while true do
			RS.Heartbeat:wait()
			local Alpha = math.min((tick() - t0) / 0.3, 1) * 90
			if (not onGround) then break end
			jumpAnim.Pos = numLerp(endJumpPos, 0, Sine(Alpha))
			jumpAnim.Rot = numLerp(endJumpRot, 0, Sine(Alpha))
			if Alpha == 90 then break end
		end
	end)
end

function onHumanoidStateChanged(oldState, newState)
	if newState == Enum.HumanoidStateType.Freefall then
		onGround = false
		if S.fallAnimation then
			onFall(HRP.Velocity.Y)
			while HRP.Velocity.Y > 0 do RS.RenderStepped:wait() end
			startFallHeight = HRP.Position.Y
		end
	elseif oldState == Enum.HumanoidStateType.Freefall then
		onGround = true
		if S.fallAnimation then
			local fallDist = startFallHeight - HRP.Position.Y
			onLand(fallDist)
		end
	end
end