0 votes

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?

in Engine by (570 points)

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

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

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

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.

1 Answer

0 votes

Node2D and Spacial nodes have a position and globalposition vector. The position is relative to their parent, while the globalposition 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.

by (212 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.