What's wrong with my GDscript for detection of collided objects group?

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

I tried to make a script that detects the collided object groups and then if the collided object is in the Wall group it’s queue_free() but i wasn’t success on that
I also tried to make it in visual script but that’s another story

my GDscript function is:

func _on_Area_body_entered(body):
	if is_in_group("Wall"):
		queue_free()

what could have gone wrong?

:bust_in_silhouette: Reply From: Zylann
func _on_Area_body_entered(body):
    if is_in_group("Wall"):
        queue_free()

Here, is_in_group("Wall") will check if the node holding this script is inside the Wall group. It does not use the body parameter at all.

But if you change it like this:

func _on_Area_body_entered(body):
    if body.is_in_group("Wall"):
        queue_free()

This will check if the colliding body is inside the Wall group. Choose the one you need.

It worked!!
Thank you so much!

Giannis1996 | 2020-03-16 20:58