[SOLVED] How can i set back the position of the player after switching and coming back i want my player when entering a shop or house and quit it to be near the door not in the original coordinates

can you please send an example i dont know how ?


Look in scene editor
I can place player in front of building to see at what position it is
And move it little to the right to see how position change
In this case we look at X position since he is on same Y position

For Y it is 350 in my case
And for X it is from 390 to 410
So it is difference of 20 pixels
So center of this doors would be at X 400

BTW you mixed X and Y

Now if i understand what you are doing
You set 1st SpawnX and SpawnY to your player X and Y positions
I just don’t know why you do it at beginning of the scene

Now i think storing them at beginning of the scene is mistake
You should store them when player is in collision with doors
And then change scene

Now payer go inside shop and leaves

And now you move player to SpawnX and SpawnY
But
Instead of change player position to GlobalVariable(SpawnX) GlobalVariable(SpawnY)

You do
Change player X position set to RandomInRange(GlobalVariable(SpawnX)-10,GlobalVariable(SpawnX)+10)

Change player Y position set to GlobalVariable(SpawnY)+10

This will give you random position of 20 pixels left to right in front of doors
And +10 pixels down away from doors

Thank you i’ma try it now and see what happend <3

Sorry for bothering you its a bit consusing tbh.Are there any example projects of this about I could take a look at?




That is what happening i tried using ur method but i think that i messed something i tried using this method from here “Scene transition help - #4 by tr4shh” and it doesnt work either

Here are My scenes in case you need them



Maybe but none i know about
But let’s start with most important question

Why you change scenes to go to shop
Instead of making shop off map?

Like imagine this

Imagine this is your town and red rectangle shows how far your player can go

Why not make inside of any building outside of your town like you see on picture above
Imagine each violet rectangle is inside of any building you wish

And now you do not need to change scenes but just switch player position when player hits building doors outside
And you just change position of player to inside of any building outside of your town
and simply
Switch it back when player hits door inside building teleporting him outside of building

Look what i did
I placed farmland here (imagine it is doors)
And then i give it instance variable called Variable and set it to number which i set to 0

Next i build let’s say inside of shop with another farmland (doors)
And give it same variable named Variable set it to number which i set to 1

Using positions of each farmlands and checking when player is in collision if Variable is equal to 0 or 1 to determine which farmland player is touching
I have 2 events which teleports player to where each farmland is using coordinates from above picture

Now walk into farmland and see how it works
In my eyes it does exactly what you are expecting WITHOUT changing scene
When you go outside (go back) you will spawn at random X position in range of 20 pixels in front of farmland and 10 pixels below it

1 Like

yeah i see its a great idea and its working super well, but for my case for a platformer game i think its hard espacially when making it like Hollow knight

(i know that its hard to make a game like that but im just saying when i fully learn how to work with GDevelop ima do it) So switching Scenes I think its the best for a platformer game anyway thank you a lot fo r helping out ima try it and see how it goes thank you so much if i ever needed something ima ask you ifts okay

No it is not
It is just option B and option A

Either you pick one or another
In your case there is no specific point even for platformer to change scenes
Which do not mean you can’t use scene switching
I just say it is pointless
Because you can clearly place inside of your shops off map like beyond it
In both cases if shop is in another scene or if it is with my method same scene but off map
You will need to adjust what map is showing like where player is
So you gain absolutely nothing by switching scenes
But it is your choice go with what suits you

hey im facing another problem LOL, Sorry For Taking so much Of Ur Time But this Is Confusing I Swear,
Well Im Using the same System that u used and i run into a problem


and the thing that when the player run into the box yes it switches place to his new cords but when i want to return the problem that he is stuck in that new place

Ps:"Also the camera im using the extension Smooth Camera(Smooth platformer Camera behavior) and it bugs a bit like she’s Following him and take like a 2-3 s Delay

Maybe you’re not updating the variable Cords of player when the player switch places, so it never goes back.

Use the normal camera events at this point to automatically force a “camera teleportation”.

How can I update it is there anyway to show me cuz this starting to confuse me again

Is your “Cords variable” a boolean variable? Check in Debugger if it’s toggling. What does it toggle 0/1?

Did you give each Box2 Cords like i did in scene editor?
I mean that Variable
Each Box2 instance should have Cords variable
You can’t just set them in events you need to set them in scene editor here
Also In your events you are checking Cords for player where you should check Cords for Box2


Let’s clear up a few things:

Firstly, creating video games isn’t a one-size-fits-all process. GDevelop shines because it lets you design through events, bypassing traditional coding. While this approach is simpler now, understanding basic game logic remains essential. This typically involves watching tutorials and embarking on many smaller projects before tackling larger ones.

Next, there seems to be some confusion. In @ZeroX4 approach, he links a variable to “door” objects (in his example, “FarmLand”), which dictates where the player ends up. Conversely, you’ve tied this variable to the player. That’s why I was thrown off, wondering if you were updating the variable… a different approach altogether. If you follow ZeroX4’s method, you’ll save yourself a lot of trouble as it’s more straightforward.

Lastly, with respect, I feel you might be rushing. Before aiming to have the player emerge in varied locations, like close to a door, it’s vital to grasp the fundamentals of possible approaches to door mechanisms. This hinges on understanding GDevelop’s variables, their functions, and their in-game implications. I’d advise diving into tutorials or examples to understand the basics (even if they don’t perfectly match what you have in mind). Otherwise, no amount of explanation, even detailed ones like these comments, will prevent you from feeling constantly confused.

Just this search in YouTube will give you a ton of information (from beginner to intermediate to advanced) about variables: GDevelop Variables Videos

hey i just woke up thank you for your replay, Man i was sleepy asf , i tried and it worked thank you so much im gonna just adjust a coupe of things, its been like a whole 3days and i was stuck on it u’re like a hero appreciating your help a lot and all the others. and if i found the solution for the other method im gonna post it here so if anyone needs it .

Hey erdo thank you for your help. im not trying to make the new undertale or hollow knight im now in the learning phase im just trying to work on new mechanics u know just to learn. im taking it slowly this one was hard so i came to ask for help im just a begginer you know. thank you for helping me out you too appreciate it <3

Hey so i just find a solution as i said i was sleepy i didnt pay goooood attention of what @ZeroX4 said so here is it :


i created a sceen variable to save the cords that i want the player position when return in o the main map where to be and used “the pause scene and start” behavior and it worked the bad thing here is for every time i should create a scene variable as here :

now it spawns the player near that checkpoints

![Capture d’écran 2023-09-13 030351|690x325]
(upload://d8TxN0jJmvfgIBDIPuRblz2kxA3.png)

the bad thing here is for every door u should create a check point or spawn point as in the photo above.

for the other scenes i checked if the player is on collision and set hes position and i used the “Stop Scene and go back to the previous one” behavior and it worked
!!! (“as u can see down here”):

i will search for an easy way to do it so thank you all for helping out thank you soooooooooooooooooooooooo much . man i love the GDevelop community you’re all better than unity’s community<3

ps:" i dont care if it was wrong but it still work and thats the matter as they say if the code works just leave it "

ps2: “i added the flip action just when he exist the store he face the other way”

Try global variables
They work between scenes