Changing Player's Position Bug

Godot Version



I set up a system where when the player enters a door, it changes the player’s position. However, when I walk through the door, it doesn’t take me where I want it to. On top of that, it tells the player’s position is exactly where I want it, but it’s outside the map. I’ve included a video to demonstrate. How can I fix this?

try check the remote’s player position

Could you please expand on that?

click the Remote tab to check runtime’s value, like here the player position

the position on inspector dock in the video only show current not runtime’s player position

It worked: changing the position through the remote tab took me to the correct location. So with this in mind, how can I achieve this through a script? (gdscript)

need to see your script how do you move the player from the “kitchen” to “little room”, might there be something not adding to the end value position you wanted

of course playerNode = $Player

try changing the .position to .global_position instead
also instead of typing exactly which position it spawns, use Marker2D to set position of spawn, get that Marker2D node global_position and use it to move the playerNode’s global_position to it

Tried playerNode.global_position = $Marker2D.global_position and it didn’t work. Is there a similar *_position I could try?

i expect it didnt work, because the Vector2() position should not reflect where it spawn as global position, because the inspector’s position only show the position, not global position

my suggestion is to make it clear and always correct by using a Marker2D or really just a Node2D as a child of the rooms for your spawn global position point reference

1 Like

The cleantable room is a node right?, you can try to remove the current teleport player code and do something like player.global_position = $CleanTable.global_position

All the rooms are just Sprites with CollisionShape2D’s on top of them. So far, I’ve tried Marker2D and putting the Sprites inside a Node2D and they both have a similar thing, where with global_position, the Node sets it to 0,0 since that’s where it is in the node, but when setting the global_position for the player, it sends it to the entire scene’s 0,0 coordinates instead.

i think you did it not right, you put the node2d/marker2d node in a position in the editor, then in script, you just need to get the global_position of it by spawnposition.global_position and put it in playerNode.global_position

So I put it where I wanted the player to teleport to, and have the player’s position set to the Marker2D’s global position, and it doesn’t work.

can i see the code for it?

now that’s strange, what does placeInsideDoor method do?

Tries to achieve something similar with this script by having one Area2D moved around via positions instead of having a ton of Area2D’s, though this in particular does not effect the player position.

if you commented that placeInsideDoor method, will it spawn where the marker position is?

Also show the player Scene in editor, did you set the player sprite to be right at 0,0 position?