Get position of an instanced scene

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

I am making a mechanic where if you press “c” once, it leaves a ghost of yourself at your position at the moment, which is just a sprite. If you press “c” again, you warp back to that ghosts position. I have it set up where when you press “c”, the ghost scene is instanced at the players position, but when I press “c” again to set it’s position back to the ghost’s, it sets its position at the parent scene, not the instanced scene. Any ideas?

Hi! can you share some of your code? its hard to know what is happening without seeing code.

p7f | 2020-08-11 18:35

Actually I just ended up doing it a different way thanks.

djmick | 2020-08-11 19:10

How about sharing what you did as the answer for other’s to learn?

tuon | 2020-08-12 22:36

I didn’t get anything as the answer, I still don’t know how to get the position of an instance. I just stopped instancing the scene, and instead just made the ghost not visible until you press ‘c’, then warping the player to the ghost’s global position.

djmick | 2020-08-12 23:06

:bust_in_silhouette: Reply From: tuon

Node2D and Spacial nodes have a position and global_position vector. The position is relative to their parent, while the global_position is its position in “world” coordinates. So you probably should use the global_position property. Also, don’t add the child node to the player or any other node that can move. When I need to add a node dynamically like this I create a parent node - like “projectiles”, or “ghosts” here - and add the node to it.

Hope this helps.