system
1
|
|
|
|
Attention |
Topic was automatically imported from the old Question2Answer platform. |
|
Asked By |
Godot_Starter |
I instance Bullets. Then I want that a enemy prints HIT if a bullet hits him. This I want to do with
func _on_Area2d_body_entered(body):
if body.get_name == "Bullet"
print("HIT")
But the problem is, that the name of the Instanced Bullet is something like @Bullet@17 and not just Bullet. How can I fix that?
system
2
|
|
|
|
Reply From: |
denxi |
A better way to do this is to use groups. When you create a bullet, add it to a group called bullets by doing something like:
bullet.add_to_group("bullets")
or by having the add_to_group("bullets")
line in the _ready()
function of the bullets script.
Then change your code to something like
func _on_Area2d_body_entered(body):
if body.is_in_group("bullets"):
print("HIT")
You can read more about groups here:
Thank you very much!
Godot_Starter | 2020-03-01 19:18