Inside the parent node "Node2D", I have the following nodes:
I want to detect when Willow's CollisionShape2D enters the interact box Area2D, as well as when it exits the area. I've tried using _on_Interactor_body_entered and _on_Interactor_body_entered without success. I want to make sure I'm only detecting when the player enters the area, not any other body that might exist later on ( otherwise I could just do get_overlapping_bodies.empty() ). How could I do this?
How to detect body entering Area2D
- Edited
Interact is a plain Node?
Is there a reason for using this structure:
Interact
.... Interact box
.... Sprite
instead of:
Interact box
.... Sprite
Connecting the Area2D's body_entered signal to the signal handler method should detect when the KinematicBody2D enters the Area2D. The signal's parameter body tells you which node entered the Area2D.
https://docs.godotengine.org/en/stable/classes/class_area2d.html#signals
- Edited
DaveTheCoder What do you mean by signal handler method?
Also, I should clarify that the Interactor is an instance of it's own scene, where it has a CollisionShape2D as a child. Whatever setup I do would need to work for any instance of the Interactor, preferably without additional setup once the instance is created.
- Edited
MouldyCheese I've tried using _on_Interactor_body_entered
Can you clarify that? Is that a function? Is a signal connected to it?
MouldyCheese What do you mean by signal handler method?
A signal has to be connected to a function (method), which is called when the signal is emitted, and handles the signal. An alternative is to call yield() to wait for the signal.
https://docs.godotengine.org/en/stable/getting_started/step_by_step/signals.html