Getting my player to spawn at a certain coordinate

Question

Im creating a practice game where a player goes into a cave and back out and I have sucessfully coded the player going in and spawning “inside the cave” and the player going back out the cave. However, I am not sure how to program the player to spawn at a certain location right next to the cave instead of its initial spawning location.

could you just create an empty node2d or 3d to mark the location you want the player to spawn at?

im not sure, i am very new to godot and coding in general so…

could either record the position and put the value into a const or put a Marker2D/3D node and get its position

Correct. You could make an empty Node3D or 2D (depends on your game) and reference that node in your player spawn script. When you call the spawn method you will just instantiate the player and set your player’s GlobalPosition to this Node3D’s GlobalPosition.

1 Like

obrázok
You can use Position2D as Spawn Point, Teleport Point, Start Position etc.

1 Like

it’s renamed to Marker2D and 3D on Godot 4

1 Like

Thanks for correction, I still work with 3.2.3 version

how would I script the teleport point?

Depends on how you’re loading in the level. If you’re adding the scene when you teleport into the cave you can use the _ready() function to move the character node to the Marker3D’s position.

Can you paste the part of the code that you’re using to switch between being inside and outside of the cave?