Lets say I have one scene called Ball.tscn . it has a script attached. Ball will be an area2D node with a collision shape node attached, and a sprite lets say.
Lets say I have another scene called Square.tscn . it has a script attached. Square will be an area2D node with a collision shape node attached, and a sprite lets say.
Upon loading my game, there will be 1 Node2D called Game, and in the ready function of a script attached to this node, I will have code that loads 5 Ball scene instances and 5 Square scene instances. Their initial positions of all of these instances will be bounded in a given area. Squares will remain in this position, while Balls will have a code giving them a linear movement away from where they start (with a random direction, lets say). The details don't matter much here.
What I planned is the following:
- For the Squares area2D, attach a signal area_entered to the Square's script. In that signal, I wanted to emit a different signal to the script Ball that entered the Square's area2D.
The main goal I want is for one instanced node to be able to identify another instanced node that entered its area. If there is a better way without signals that accomplishes this, that would also be equally helpful.
When nodes aren't instanced, its easy enough to connect them via script or through the signal drop down, but for instanced nodes, I don't know how to reference them. Usually I just use get_node("/root/Game/_____") to reference a node that is already in the game. Or if it is just one instance, usually it has the name of its root node, so I can "anticipate" what it will be called. But when I instance a bunch of nodes, they receive different names that start with @ symbols, and I don't know how via code to reference these nodes. Knowing this would also be VERY helpful.
Finally, to clarify, I don't want to send a signal to ALL Ball instances if the square's area2D is entered. I only want the signal to send to the Ball instance that entered the square's area2D.
Any help is greatly appreciated, this is a huge gap in my knowledge that is halting my progress with my game.