getting the group of a collided object

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

The _on_body_entered signal seems to work backwards to how I need it. I have a grappling hook (Rigid body 2D) that needs to know the group of the thing it collides with, but for some reason the following code returns the group of the hook itself.

func _on_Hook_body_entered(body):
if body.is_in_group(“surface”):
do stuff

I’ve struggled with signals since starting with godot. Is there a smarter way to detect when the hook collides with something and then get the group of that something?

what do you mean by “returns the group of the hook itself”? i don’t see anything in that block of code that would return a group name.

Eric Ellingson | 2020-03-11 23:43

I should just close this down. It now works. I could not tell you what I changed.

demon3o5z | 2020-03-13 00:58

:bust_in_silhouette: Reply From: Merlin1846
func on_Hook_body_entered(body):
    if body.is_in_group("surface"):
        #Whatever you need to do.

Their could be anything wrong but lets start.

1.Is the collision shape or the parent of the collision shape in the group?
–If so then you may need to do

if body.get_parent().is_in_group("surface"):
  1. If it is a tilemap then make sure the tilemap is in a group.
    –if it’s not then nothing will make it work except adding it to a group.

if none of these work or are the problem then tell me.

Thanks for the response, but it works now. And I could not tell you what I changed.

demon3o5z | 2020-03-13 00:59

1 Like