Is there a way to get position of multiple instanced objects?

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

My Root node was set up like this

World

  • Player
  • object
  • object2
  • object3
  • object4

My player has a certain area and when an object enters it prints out the position of the original object. I tried using get_node(“/root/World/object”).get_position()

But object is an instanced scene and I have several object2, object3, object4. Even if object2 enters the area of my player it still prints the position of the original object.

:bust_in_silhouette: Reply From: MrEliptik

When using the signal from your player’s area, you get the body entering it. You can use it to print it’s position. Assuming it’s a 2D game:

_on_Area2D_body_entered(body):
    print(body.global_position)