You probably want to have a boolean you set when you are in the air, and then you can detect if that boolean is true when hitting the ground to detect if you just hit the ground. Something like this:
if is_on_floor():
if (is_in_air == true):
is_in_air = false
$AnimationPlayer.play("Ground_Collide")
else:
is_in_air = true
If you want to make sure the animation plays, I'd recommend having a boolean that "locks" the animation until it is finished. You can use the animation_finished
signal to unlock the boolean once the animation is done. I would use a couple functions for this:
# the variable for locking the animation
var animation_lock = false
# connect the animation_finished signal in _ready
func _ready():
$AnimationPlayer.connect("animation_finished", self, "on_animation_finished")
func play_animation(animation_name, add_lock_animation=false):
if (animation_lock == true):
return
$AnimationPlayer.play(animation_name)
animation_lock = add_lock_animation
func on_animation_finished(_animation_name):
animation_lock = false
Then instead of calling AnimationPlayer.play
in your player code, you'll instead want to call play_animation
, optionally passing the second argument as true
when you want to lock the animation so it can play fully. :smile: