Detect when a part has landed

I have a part and a player attached to it, i want to check if the part has landed (aka was falling before) and play an animation on the player. The humanoid has platformStand on so i cannot use StateChanged event.

I’ve tried raycasting but its really buggy sometimes even playing the animations like 5-6 times.

Can you provide code so i can see what you have done?

1 Like

Maybe something like this could work?

local fallVelocityThreshold = 20 -- Minimum required velocity to be considered a fall
local part = script.Parent

part.Touched:Connect(function(otherPart: BasePart)
	if math.abs(part.AssemblyLinearVelocity.Y) < fallVelocityThreshold then
		return
	end
	
	local partPos = part.Position
	
	-- Check if otherpart is above part
	if otherPart:GetClosestPointOnSurface(partPos).Y > partPos.Y then
		return
	end
	
	print("landed")
end)

Your original method might work too if you added a debounce to it.

1 Like

I’m sure this can be fixed with a debounce – could you send your code?

I am curious why you would want to use raycasting in this scenario? @nowodev has the right idea. The idea is to detect when a part has landed after falling. There has to be an origin position of where the part originally started from and you can just work with it from there. I don’t see the use for raycasting here. I recently just added raycasting to my new game as a way of detecting character’s who are underneath a part. Rays operate the same way a camera does. You take a picture and it detects whatever is in that direction. We don’t know what his game looks like but if his raycast is playing the animation multiple times it makes me think there is other things obstructing the view of the raycast and it can become a real hassle to exclude everything from its path with the canquery property unless you really know what you’re doing. A simple position detection could be ideal here but we won’t know for sure until the OP responds. There are clear instructions how to make a post in scripting support. OP should provide basic information about the game.

I mean it could work i suppose, but is there another way to do it without using .Touched, since from what i know .Touched isnt very fast and accurate, of course i could be wrong.

.Touched should fire immediately when the engine detects a collision, you can try going back to raycasting again if you wish.

Alr, im using physics to move the part in my game so from what you said, i understand that .Touched fires when the physics engine detects a collision, which should be ideal. Thanks a lot for the help