How to store player location and call at anytime?

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

So, I’m new to Godot and I have a little battle RPG going on. Whenever you walk into an enemy, you get sent to a different scene, but once you go back, you get sent back to the starting point where the character is originally in the game.

Does anyone have any useful code or information to help me:
a) store the location of my character
b) use this location to send my character to the exact location?

I am using Godot 3.2

:bust_in_silhouette: Reply From: Magso

For 2D there’s position & global_position. For 3D there’s translation, transform.origin & global_transform.origin. Each have set and get methods.
Examples of each.

var pos = sprite.get_global_position()
var pos = kinematic_body.get_translation()

Hi. I am having the same problem as the op. I want to move my player scene onto the correct position when the player exits the shop and I don’t know how to do it.
Is there a way you can explain how to do change the position of a kinematic body when you change to another scene? By the way Im making a 2D rpg like Zelda LTTP

AdrianeX | 2020-09-22 21:37

You need to store the position somewhere it can be set once you enter the main scene.
If you’re using get_tree().change_scene() or get_tree().change_scene_to() the position can be stored in a singleton.
If you’re using add_child() and remove_child() the position can be stored on the player.
As the player leaves a shop have the script where the position is stored to set the player position.

Magso | 2020-09-22 22:16