How can I detect collisions with a specific node or scene

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

I want to create an inspection system for my game, for example:
You walk up to a desk and press an input and a text box pops up, something simple like that. However, I have been trying all day to make it so my Area2D (seperate from my kinematicbody2D used for physics) can detect the exact scene/node it is colliding with. I have tried filtering names, and groups, I have followed almost every tutorial I can find, and scanned the docs for some sort of answer, yet frustratingly, absolutely nothing I try is working. So all I’m asking is how I can get it so that, if my area 2D is colliding with my door (Area2D), it will do something that won’t happen when it’s colliding with my a different Area2D and vice versa.

Names and groups and even layers should work for this. Is there any code that you have for this?

exuin | 2021-06-17 20:28

Here:

func _ready():
	var collider = $Area2D # The child Area2D node. Mine's Area2D
	collider.connect("area_entered", _collide)
# ...
func _collide(collider2: Area2D):
	if collider2.get_parent() == get_node("/root/(SceneNode)/(Node)"):
		lose()

If this doesn’t work, tell me!