is not working

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

Hello. I am making a 2d platformer where there is an enemy. My enemy is an area 2d it moves left and right. If the player touches the player takes damage but when a bullet touches it dies. the names of my player and bullet scene is “Player” and “Bullet” respectively.(just a note my bullet is an area 2d)

so here is my code for detection of player and the bullet

func _on_Area2D_body_entered(body):
if body.get_name() == "Bullet":
if body.get_name() == "Player":

however, my bullet does not disappear after hitting my enemy and my player is also going through the enemy without reloading the scene.

bullet collision layer 2 mask 2
enemy collision layer 1&2 mask 1&2
player collision layer 1 mask 1

so how should I do this?

:bust_in_silhouette: Reply From: Whom

Assuming the function is in your enemy script, you only call queue_free for the enemy, not for the bullet. And have checked that PhysicsBody2D node of the player scene is actually named “Player”?

I checked and the kinematicbody2d node of the player was spelled wrongly causing the issue, however, it still does not work. My bullet disappears when it hits anything but for some reason nothing is happening. How should I go about this??? and just a question is an area 2d considered a body?

GodotUser21 | 2022-10-25 11:54

No, Area2D is not a body. Body2D refers to KinematicBody2D, RigidBody2D or StaticBody2D. If you need to detect another Area2D, you should use area_entered(area) and if you need to detect a body node, use body_entered(body). See docs.

Whom | 2022-10-29 07:55

Thanks so much :slight_smile:

GodotUser21 | 2022-10-31 02:04