Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | NelsonSMG |
Hi,
I’m making a 2d fps minigame, the way it works it’s pretty simple:
When the player “shoots”, it instances a bullet scene, which is an area2d.
The bullet then checks, in _physics_process, if it’s inside another area2d using get_overlapping_areas(), which returns an array. The bullet then queue_frees itself if hits or after a period of time.
The first object of the array gets “hit”.
Here’s the problem:
At first, when instancing the bullet scene, I made it a child of the root node (using level = get_tree().root.get_child(0)
, level = get_node("root/level) or any other method
then level.add_child(new_bullet)
), but then the overlapping areas’d return an empty array, even if it’s inside the target.
However if I made the bullet a child of the player, with self.add_child(new_bullet)
, then the function returns the array with the target inside.
The problem is solved, but I still wanna know why the first method didn’t work, did I get the root node incorrectly?
The layers are setup correctly, since the 2nd method worked.
Ty