+2 votes

Im still new in godot, and im trying to change scenes using Area2D node. With my code, im able to switch scenes back and forth.

Heres my code :

extends Area2D
export(String, FILE, "*.tscn" ) var next_world

func _physics_process(_delta):
    if get_overlapping_bodies().size() > 0:
        get_tree().change_scene(next_world)

However, by using this code, the player will only appear based from where i placed his node inside of the scene, which is not what i wanted for scenes with multiple entrances. is there any way to make the player appear in a specific location in the scene using the Area2D node? (which in my case is in front of the node) Or do you need another node to do so?
Because i couldnt seem to find any guides/tutorials regarding this.

in Engine by (18 points)

3 Answers

0 votes

I'm having this exact same problem and I haven't found a real good answer to it. My solution was to put everything in the same scene far away from each other and then teleport between the areas by using doors. That kept things loaded for each area but I think the map creation would be much more easy if I could make a new scene for each area. Let me link you to my question so that we can keep each other updated.

https://godotengine.org/qa/76195/how-save-the-positions-instances-scene-come-back-them-later

by (26 points)
0 votes

Your player will be a child of the new scene, will it not? I guess you could write a line of code in the _ready() function of the newly instanciated scene in which you can specify where you want the player to appear.

Alternatively, you could keep the characters position in each scene in a global variable (called singleton in Godot) and have your Aread2D nodes check it every time you change scenes.

by (1,859 points)
edited by
0 votes

I also ran into this problem recently for a top down 2D rpg and ended up making a teleport system that allows a player to move from one specific area2d to another (in any scene).

I wrote about it in more detail in a blog post here: https://4days.dev/devlog/2021/12/26/breaking-and-entering.html

Maybe somebody will find it helpful.

by (38 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.