0

enter image description here

I'm making a player's death system, but when the enemy collide with the player, nothing happens, well... it print in log how many life's left but its just it, i have created the area 2D group (Hurtbox) and (power(The enemy's area group)), colissionshape and everything else

STA
  • 30,729
  • 8
  • 45
  • 59
  • So to be clear. The life is printed in the console? If yes, your collision seems to work fine, because you wouldn't have that log otherwise (given by the code you posted). Then I would check your Animationplayer. – Bugfish Feb 05 '21 at 09:00

1 Answers1

1

Play the animation and yield:

    if life == 0:
        $Spritezada.play("Dead")
        yield($Spritezada, "animation_finished")
        print("died")
        queue_free()

The above code will play the animation, then halt the execution. When the animation player raises the signal animation_finished it will resume, print "died" and set the current node for removal (queue_free).


By the way, the animation_finished signal passes a text parameter. If you do not want to use yield as suggested above, write your code like so:

func _on_Spritezada_animation_finished(anim_name: String):
    if anim_name == "Dead":
        queue_free()

I believe Godot should be telling you about that missing parameter. If you don't see a message about that, double check you connected the correct signal.

Theraot
  • 31,890
  • 5
  • 57
  • 86