How do I teleport the player to specific position after interacting with something?

Godot Version

Godot 4.4.1

Question

` I want to send the player to another room of their house after interacting with a door, but if i try to set their position with global_position, it doesn’t work and their position is just wherever the player node in the second scene is. I tried to circumvent this by making the player a global but this breaks a lot of things instantly
heres the script that allows you to interact with a door and the scene tree (it’s basically the same between both scenes so i didn’t share both)


`

I don’t see any code that changes the player position here.

Presumably you’re just setting the position of the player and then deleting the player along with the scene, and creating a new player in the new scene.

i just left it out since no solutions actually worked, but ya i think that’s whatsh appening.. i don’t know a way to not do that though

There are basically two ways about it:

  1. Put the player somewhere it won’t be removed with the scene or detach the player from the scene before removing, and then add the player back to the new level when the level is loaded.
  2. Simply store the player’s position somewhere, and set the position after the new scene has loaded.

Which is preferable depends on your case.

In my case, for example, the player is not part of the level. Instead, the level contains a Marker that signifies the player’s starting position (for example), and then someone (the scene that handles setting up the level) sets up the player separately and sets the position to the marker’s position.