Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
425 views
in Technique[技术] by (71.8m points)

2d - Godot2D How can i make the enemy's attack collision work

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

question from:https://stackoverflow.com/questions/66047768/godot2d-how-can-i-make-the-enemys-attack-collision-work

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...