How to delete the exact brick which ball collided with?

Godot Version

` 4.4

Question

Hello everyone. New to godot trying to make arkanoid game, had trouble with deleting brick on screen. I have scene with brick which i instantiate to main scene and duplicate to make more bricks. I tried to add them to group and nothing seems to work. It works if I type each brick as condition to collider but send an error, i guess because my bricks is from another scene and i instantiated them. It has to be another the way to delete the brick the ball collided with rather then just typing all of them in collider == $“…/Brick” or collider == $“…/Brick2” or collider == $“…/Brick3” or collider == $“…/Brick4” or collider == $“…/Brick5” How i can do that?

One thing I sometimes do in situations like this is add a method to the brick_scene that does nothing, like the following:

func is_brick():
    pass

And then change your elif collider == .... condition with ```elif collider.has_method(“is_brick”):".

I don’t know if this practice is frowned upon, though :smiley:

I would create a ball scene (prefab) and add it to a “ball” group. Then create a brick scene and add it to the “brick” group.

There are a couple ways to proceed…

In the brick scene, check if the colliding object is in the “ball” group, and remove the brick via queue_free().

Or in the ball scene, check if the colliding object is in the brick group, and remove the object the ball collided with.

Adding on to this it would seem your bricks already have a group, you do not need to get the brick node, only check the collider’s group

elif collider.is_in_group("brick"):
    dir = dir.bounce(collision.get_normal())
    collider.queue_free()

Make sure to paste code instead of screenshots

Wow somehow that works. I’m pretty sure i tried this before and it breaks only one brick, now all works the way it should be. Thank you for your help!
Collision is tough thing for me to understand now