0 votes

I have a problem: I made a bullet, added as a child node, when you press space bullet is being added as a child, point is to shoot asteroids which split in half, i set asteroids to react
if area.get_name =="bullet" but then the problem is that only the first bullet is named "bullet" other ones when generated are named like @bullet@34 etc. how should I make asteroids react to every bullet, what should I do???

in Engine by (46 points)

1 Answer

+2 votes
Best answer

Names must be unique among sibling nodes.

For a situation like this, groups are an ideal solution. Put your bullet in a group called "bullets", and then you can do

if area.is_in_group("bullets"):

Another solution is to use

class_name Bullet

in the top of the bullet's script and then you can do

if area is Bullet:
by (19,949 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.