How to detect when the Player has first landed to generate a foot dust particle effect

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By JayH

Hi,

Just as the title says, I’d like to know the best way to determine when the Player has first hit the ground. This way I can generate some game juice with foot dust.

I understand that I may be able to use a boolean test, but perhaps there is a more straight-forward way.

enter image description here

Here’s my grounded code:



#SET IF ON THE GROUND OR NOT
	if is_on_floor() :
		onGround = true
	else:
		onGround = false
		if myVelocity.y < 0:
			$AnimatedSprite.play("Jump")
		if myVelocity.y > 0 :
			$AnimatedSprite.play("Fall")
			

	myVelocity = move_and_slide(myVelocity, FLOOR) #MOVE PLAYER WALKING

What are your suggestions?

Thanks.

:bust_in_silhouette: Reply From: DaddyMonster

You’re 99% there. You want to pick up the first frame that is_on_floor()fires. You’ve got an onGround bool, which switches from false to true the first time you hit the ground.

Therefore, only on the first frame will is_on_floor() be true and onGround be false. So, use that fact:

if is_on_floor() :
    if not onGround:
       make_dust()
    onGround = true

That’s great, thanks. So simple, yet does the job!

JayH | 2022-07-25 06:39