0 votes

I'm making a horror game and each scene is separated by a door. By that, I mean that each door leads to a scene. What I've been doing for now is just changing the scene when interacting with a door, and then use a Kinematic Body that was already in the new scene to continue playing.
The problem I'm having is that when going back to the previous scene, since I already had a Kinematic Body, the player appears in the beginning of the scene, when I actually want the player to appear in front of the door it just entered through.

I wanted to fix the issue by creating a global script with a variable that controls the player's position and then change its value from the Raycast script (which changes the scene) so it appears in a different position based on what door the Raycast collides with, but I don't know how to make a variable that controls that through another script
I'm changing the position through code because I need to change it when the player is in another scene and I need a global variable to do that. I would also like to keep the layout of different scenes for each map because I feel more comfortable working that way.

Here's part of the Raycast script which changes the scene when colliding with a specific door, and the part of the player's script which controls the movement.
Raycast script:

if obj.get_name() == "Scene3Door1Area" and Input.is_action_just_pressed("Interact"):
    get_node("../../../../Control/FadeInOut/AnimationPlayer").play("FadeOut") #Fade out
    yield(get_tree().create_timer(1), "timeout")
    get_tree().change_scene("res://Scenes/Game levels and scenes/Game_2.tscn")
    # get_node("../../..").translate(Vector3(20.229, -2.943, -124.483)) (I want to move the player to this position when it's in the other scene)

Player movement script:

# Walking
dir = Vector3()
var cam_xform = camera.get_global_transform()
var input_movement_vector = Vector2()
if Input.is_action_pressed("movement_forward"):
    input_movement_vector.y += 1
    if $Walking.is_playing() == false:
if Input.is_action_just_released("movement_forward"):
if Input.is_action_pressed("movement_backward"):
    input_movement_vector.y -= 1
if Input.is_action_pressed("movement_left"):
    input_movement_vector.x -= 1
if Input.is_action_pressed("movement_right"):
    input_movement_vector.x += 1

Any help would be appreciated

Godot version v 3.4.2
in Engine by (20 points)

1 Answer

0 votes
Best answer

Do You know about Autoload ? If You change scenes by replacing them completely, Autoload is pretty much your only option for global data. You will have to pass position from Raycast to Autoloaded script, and every scene will have to read this position from Autoload upon instancing. Learn about Autoload from docs and feel free to ask if You have any doubts how to implement this sollution

by (5,136 points)
selected by
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.