In my project, I have a bullet that can destroy 2 types of objects: Enemies and Targets.
The problem is that after I destroy a single object, I can’t destroy anything eles again, even objects of the same type
The code for both objects (note: bolinha is the name of the projectile):
func _on_collision_body_entered(body):
if body.get_name() == “bolinha”:
queue_free()
if your projectile scene has a root with a script, add class_name name, to the top of the file.
then when you handle the collision event try:
_func_on_collision_body_entered(body)
if body is name
queue_free()
name in the above example should be something you want to use to identify the object ex: projectile
The file of the projectile’s script?
yes, either before or after the extends line. so something like
extends Area2d
class_name projectile
although im not entirely convinced this will solve your problem as you may have other issues relating to spawning objects and or self collisions
It’s not working even on the script

Even thoug I named it

I’m not a GDScript user so I don’t know the syntax, but have you tried doing:
if body.name is "projectile":
queue_free()
or
if body is "projectile":
queue_free()
Could you try printing out the type of the body
to confirm that it is, in fact, projectile
?:
print(body.get_class())
Also are you sure you are spawning more than 1 projectile into your main scene?
Are you freeing projectile scenes in other scripts or scenes?
Do spawned projectiles have the correct speed and direction?
As you can see there are so many things that can trip you up
Also are you sure you are spawning more than 1 projectile into your main scene? Yes
Are you freeing projectile scenes in other scripts or scenes? No, I think
Do spawned projectiles have the correct speed and direction? No actually, im working on that
That seems problematic that youre sending a tilemap for the argument of the collision check, but i cant say for sure because i dont know how your game is structured
1 Like
Yes, it would be nice to know what your node tree looks like in all the relevant scenes.
Pictures, pictures, pictures!
You forgot to attach an image of the thing we’re talking about.
Please attach an image for the bullet’s node tree.
Okay. So your bullet is a CharacterBody2D
.
If you compare this to the fact that your area is only hitting a TileMap
, you will realize that the bullet is not detected by the area.
More questions:
- Why do you have two
Area2D
s (collision
and Bullet_collision
)?
- What are they used for?
- The same goes for your
Inimigo
object. Why does it have two Area2D
s?
- Why is
collision
the only Area2D
with a signal connection (denoted by the signal icon)?
it feels like those scenes for target and enemy have extraneous collisionShape2D nodes. You may want to start there and remove them.
As an example here is my enemy_scene tree ( i call it entity)

I don’t rememer what the multiple colisions were for on the Target, but on the Enemy, one of them was for player detection
Also, I found a way to fix the issue by assingn the projectile to a group and using “if body.is_in_group(“projectile”):” instead of “if body.get_name() == “bolinha”:”