I am working on a fall script

You can write your topic however you want, but you need to answer these questions:

  1. when the player jumps a animation plays, when they land depending on how far they fell from either a light landing animation will play or a heavy landing animation simulating they just fell from a great height

  2. the issue is, it wants to play the big landing twice in a row, before registering small landings, so i can jump from a high place and get the big landing animation and then jump from a small place and get the big animation again, only after that does it start to register small animations

local plyr = game.Players.LocalPlayer
local char = plyr.Character or plyr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local hr = char:WaitForChild("HumanoidRootPart")
local jump =  hum:LoadAnimation(script:WaitForChild("Jump"))
local walk = script:WaitForChild("Walk")
local run = script:WaitForChild("Run")
local idle = script:WaitForChild("Idle")
local freefall = hum:LoadAnimation(script:WaitForChild("FreeFall"))
local maybigfall = false
local initpos = nil


function AdvancedJumpDetection()
	
end

hum.StateChanged:connect(function(oldstate, newstate)
	if newstate == Enum.HumanoidStateType.Jumping then
		jump:Play()
		initpos = hr.Position 
		hum.FreeFalling:connect(function()
			if maybigfall == false then
			local currentpos = hr.Position
			local distancefell = (initpos-currentpos).magnitude
				print(distancefell)
				if distancefell >= 30 then
					maybigfall = true	
				elseif distancefell < 30 then
					maybigfall = false
					
				end
			else
			
			end
		end)
		
		
		
	elseif newstate == Enum.HumanoidStateType.Landed then
		jump:Stop()
		if maybigfall == false then
			maybigfall = false
			print("small fall")
			spawn(function()
				hum.JumpPower = 0
				wait(2)
				hum.JumpPower = 50
			end)
			hum:LoadAnimation(script:WaitForChild("RegFall")):Play()
			
		elseif maybigfall == true then
			print("bigfall")
			maybigfall = false
			hum:LoadAnimation(script:WaitForChild("BigFall")):Play()
			spawn(function()
				hum.JumpPower = 0
				hum.WalkSpeed = 0
				wait(2)
				hum.JumpPower = 50
				hum.WalkSpeed = 16
			end)
		
		end
		
	end
end)

I just want it to properly and reliably differentiate between if it should play the light landing or heavy landing animation

Hmmm… looks like it has to do with how you’re detecting the state changes, and how you’re detecting the height. I can’t quite explain what was wrong with the code you posted since I’m a bit sleepy, but I can tell you how I’d approach this kind of problem.

What you want would be to get the distance from the highest point of the fall, then start checking the y distance from that height. You start with the light landing animation, and if it gets past a certain distance, that’s when you play the heavy landing animation.

There’s no need to know when the jump started, or what’s causing the fall – all you need to care about is that the Humanoid is falling, and you need to know what animation to play when it lands.

Kinda like this:

local trackingHeight = false 
local maxHeight = 0
local HEAVY_LANDING_HEIGHT = 30 -- this is how far you need to fall to trigger a heavy landing 
local landingAnimation = LIGHT_LANDING_ANIMATION
Humanoid.FreeFalling:Connect(function()
	-- check if we're already tracking the height
	if not trackingHeight then 
		-- debounce 
		trackingHeight = true 
		-- run this loop while the humanoid is in the freefall state 
		while Humanoid:GetState() == Enum.HumanoidStateType.Freefall do 
			-- get current height
			local currentHeight = HumanoidRootPart.Position.Y
			
			-- now check if height is going up or down
			if currentHeight > maxHeight then 
				-- we're going up, so keep increasing maxHeight
				maxHeight = currentHeight
			else
				-- we're going down now, so check the distance and change the animation 
				local fallenDistance = maxHeight - currentHeight
				if fallenDistance > HEAVY_LANDING_HEIGHT then 
					landingAnimation = HEAVY_LANDING_ANIMATION
				else 
					landingAnimation = LIGHT_LANDING_ANIMATION
				end
			end
			task.wait()
		end
		trackingHeight = false 
	end
end)

Oh wow I’ll try this I did get mine working, but if this is the better way of doing it I might as well use it

1 Like