Detecting area2d colliding object

Godot Version

Godot4.2

Question

Hello, I’m totally new to godot, I was trying to make coins but as I collide with them, they do me damage like any other entities, so I wanted to filter the colliding element, but I can’t recover the name of the entity that touched me (either monster or coin) I’ll let you look at the images of my attempt which I hope you will understand. THANKS (Srry for my english)

(Below is what print(body.name) returns)
image

(My character is an area2d, monsters are rigidbody2d and my coins are staticbody2d)
(For detecting collision I use _on_body_entered(body))

You can simply put all monsters in the group “monsters” (Inspector > Node > Groups) and coins to “coins”. Then you would improve the collision detection a bit:

func _on_body_entered(body):
    if body.is_in_group("monsters"):
        # player was damaged
    elif body.is_in_group("coins"):
        # collect the coin
1 Like

Thank you very much you solved my problem and learned a great feature
Have a good day

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.