• 3D
  • Help with changing the player's position when it's in different scenes

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:
			$Walking.play()
	if Input.is_action_just_released("movement_forward"):
		$Walking.stop()
	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

14 days later

Have you looked at the (sorta-) Singletons offered via the project AutoLoad? It seems to be what you're describing.