[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

i want my player when entering a shop or house and quit it to be near the door not in the original cordinates

You can go with RandomInRange(MinValiue,MaxValue)

So for example looking at outside of shop
Doors are at X 50 and Y 300

You could change player position to
X RandomInRange(50,60)
Y 310

So it will be teleported to random position of 10 pixels in front of doors between 50 and 60 pixels

While it will also be teleported 10 pixels down from the door

Numbers can be adjusted

You could always go simple and do something “Set X Position to ------.” That should work, and then you can just pick whatever X coordinate you want, then do the same for the Y position.

Also, thanks for asking this, because I just figured out what was wrong with mine, so once again, thanks!

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
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