|
|
|
|
Reply From: |
Bernard Cloutier |
If I understand correctly, in one scene you have a player somewhere on your tilemap. Then you want to switch to another scene, and when you come back you would like your player to be in the same place he was, right?
The tilemap’s origin is always going to be the same. Why aren’t you storing the player’s position instead? Like this: GlobalP.player_position = $Player.position
(I’m assuming your node is called Player and is at the same level as Tilemap. Since you haven’t shared your scene tree, I cannot know for sure that the $Player
path will be correct).
You got it right, but i’m still returning to the starting point.
I’ve stored the position your way, but now i need it to position my player according to it when entering the TileMap scene.
How about this:
in your player script
func _ready():
if GlobalP.player_position not null:
self.position = GlobalP.player_position
Just remember, setting GlobalP.player_position
only copies the current value of your player position. If you change the player’s position, the value in GlobalP.player_position
will not change. So I don’t think you should set GlobalP.player_position
in a _ready
function, you should set it just before you switch scene.
Bernard Cloutier | 2020-02-24 19:08
Ok, tried to put those lines in my player script, but strangely, got this error:
‘:’ expected at end of line.
When ‘:’ is obviously at the end of the line…
My bad, this is the correct version:
func _ready():
if GlobalP.player_position != null:
self.position = GlobalP.player_position
Bernard Cloutier | 2020-02-24 19:24
Here we are! Cheeeeeeeeeeers!