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.
if obj.get_name() == "Scene3Door1Area" and Input.is_action_just_pressed("Interact"):
get_node("../../../../Control/FadeInOut/AnimationPlayer").play("FadeOut") #Fade out
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:
dir = Vector3()
var cam_xform = camera.get_global_transform()
var input_movement_vector = Vector2()
input_movement_vector.y += 1
if $Walking.is_playing() == false:
input_movement_vector.y -= 1
input_movement_vector.x -= 1
input_movement_vector.x += 1
Any help would be appreciated