Hi there,

I was able to make code which switches scenes when a KinematicBody enters an Area node. But I also need a line of code that teleports the player when he steps into a different area and it changes the scene but teleports the player to a new spawnpoint.

So something like this:

Player Steps In Scene Changer 1 > Outcome 1 > Location X = 20, Y = 12, Z = 30 Player Steps In Scene Changer 2 > Outcome 2 > Location X = 40, Y= 12, Z = 5 etc.

I do think the outcomes need be scene connected or something like that but I am not sure on that. for example:

Exits HouseScene1 > Outcome WorldScene2 Enters WorldScene4 > Outcome LevelScene1

this is the code that changes the scene when body has entered the area:

extends Area

var _is_player_in_Area = false
export (String) var player_node_name = "Player"
signal on_player_entered
var _start_new_scene = false

func _ready():
    connect("body_entered",self,"_on_Scene_Load")
    connect("on_player_entered",self,"_Print_Load");

func _process(delta):
    if _is_player_in_Area == true:
        emit_signal("on_player_entered")
        _start_new_scene = true
        get_tree().change_scene("res://Scenes/Scenes 3D/Title Screen/Title/MENU.tscn")

    
func _on_Scene_Load(other):
    if other.name == player_node_name:
        _is_player_in_Area = true

    
func _Print_Load():
    print ("Load Scene!");

Thanks for the help :P

Edited the post to better format the code since you were using inline code formatting, hope you don't mind.

The way I have handled this kind of thing in the past is to have a singleton/autoload script store the location to spawn the player at across scenes. Something like this:

var player_position = null
# optional
var player_rotation = null

Then in the player script, I have something like the following in _ready (assuming the singleton is called Globals):

func _ready():
	if (Globals.player_position != null):
		global_transform.origin = Globals.player_position
	if (Globals.player_rotation != null):
		rotation_degrees = Globals.player_rotation

Finally, in the thing that changes the scene, I use something like the following:

export (Vector3) var position_in_next_scene = null
export (Vector3) var rotation_in_next_scene = null

# Other code

func change_scene():
	Globals.player_position = position_in_next_scene
	Globals.player_rotation = rotation_in_next_scene

There probably are better ways of handling it, but something like the code above is what I have used in several games and it works okay. The biggest downside is the data entry is a little time consuming.

@KindosaurGaming said: @TwistedTwigleg Hello again

I asked the same question on the Q&A forum of godot and got an answer on this question aswell

It is a different approach which uses a dictionary to discribe where sertain spawn areas are. Is this a good solution as well

Seems like a good solution. From what I can gather, the idea is that you place all of the locations (and rotations) into a dictionary in a singleton, which would make it where you can link the position to a name, which might make using it a little easier to use and since everything is in one place (both a pro and a con) there is no scene hopping trying to figure out what goes where.

The only, albeit minor, downside with placing all the locations into a dictionary is that depending on how many locations you have stored, managing the dictionary in code and finding specific locations may become a little more difficult. Not a huge issue, but if you have dozens of locations, it may be something to be aware of.

@TwistedTwigleg I do want to implement around 7 islands

Maybe I can try to give each Island a separate Scene (or even file) and only transfer the player data.

3 years later