0 votes

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

in Engine by (12 points)

1 Answer

+2 votes

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()
by (3,225 points)

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

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.

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.