enemy (object) destroy

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

How do I make enemy die?
player collided the enemy but player died.
I do not want to die player
Sorry I write badly

code:

extends KinematicBody2D
...
...
...
func _on_Area2D_body_entered(body):
	
	body.queue_free()

	pass
:bust_in_silhouette: Reply From: MysteryGM
func _on_Area2D_body_entered(body):
body.queue_free()

This is actually correct, the problem here is how your collisions are assigned. I find that everything in Godot works in reverse from what is expected.

The player needs to have the collision code.
I have a player and attached to it is the Area2D, I then add a code to my player and link the signal of the On_Entered with itself.

After this the code looks like this:

func _on_Player_body_entered(body):
body.queue_free()

Now the player destroys the other objects, instead of each object destroying itself. It is all reversed.

In your situation you could try:

func _on_Player_body_entered(body):
  self.queue_free()

Thank!
I’m going to study more because i use little godot.

Skyline | 2018-10-02 17:51