Best way to set a position of a node based on a variable?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ralime
:warning: Old Version Published before Godot 3 was released.

I’m creating a platformer, and when the player enter a door, and go to the next level(scene), and travel back. He end’s in the same, predefined position. (The start of the stage) How can i change the position of the character node based on a variable? (Or call a node to appear in a place, with a script?) thanks! And sorry if i was not clear (english is not my native language)

:bust_in_silhouette: Reply From: eons

If the player can go back and forth, sometimes is good to not free the old scene, just remove from the tree and keep it ready to go back in, the previous level can have a variable saying which exit the player took, could be a vector storing local/global position (that may work up to a simple metroidvania).

Having all neighbour stages already on the tree is useful too, if the stages are not too big/complex, of course.


But a better structure may be needed for complex designs, something like a script with the full stage structure, linking different exits.

You can create a stage manager that takes care of loading, storing and removing/freeing stages and the script with the exit links.