moving a global position using another node's global position

Godot Version

4.6.3

Question

i’m trying to create a system for a 2d top down rpg within godot, inspired by rpgmaker games. right now my focus is on writing a script that makes the player teleport to a new position within a scene upon pressing a key to open a door in the overworld. this is the layout of my test map scene:


actionable and actionable2 are npcs that have functioning dialogue via dialogue manager. i’m not concerned with them right now. the collisionshape2d is the area that is interactable by the player. i want actionable3 to teleport the player to the global position of teleport_pos after interacting with the collisionshape2d. this is the part of the player script for handling inputs:

func _unhandled_input(event: InputEvent) -> void:
	if Input.is_action_just_pressed("ui_accept"):
		var actionables = actionable_finder.get_overlapping_areas()
		if actionables.size() > 0:
			actionables[0].action(self)
			return
	if _moving:
		return
	for dir in inputs.keys():
		if event.is_action_pressed(dir):
			_try_move(inputs[dir])
			return #only one direction per input event

and this is all of my current actionable script:

extends Area2D

enum a {NPC, ROOM_CHANGER, SCENE_CHANGER}
@export var dialogue_resource: DialogueResource
@export var dialogue_start: String = "start"
@export var actionable_type: a

@export_file var nextScene
@export var nextPos : Node2D

func action(player: CharacterBody2D) -> void:
	if actionable_type == a.NPC:
		DialogueManager.show_example_dialogue_balloon(dialogue_resource, dialogue_start)
	elif actionable_type == a.ROOM_CHANGER:
		player.global_position = nextPos.global_position
	else:
		pass

i’ll deal with the SCENE_CHANGER mode later. i just want to deal with the ROOM_CHANGER mode right now.

so my question is: what’s the right way to handle this? is this the right way to think about it?
thank you!

Likely should be looking for input at the collision shape level. I would do that and send out a signal for the player to intercept when the input happened.

Great question. Have you followed a good top down rpg tutorial for Godot yet? I’m sure there are many.

Thing is, based on your code here I’m inclined to say: “sure, you’re doing fine. Please rename your Area2D nodes to something more meaningful”

But I am sure there is a good opinionated way to do all this stuff because it has been done so many times before. If you’re introduced to one good solid opinionated system that covers all your top down rpg Godot bases, you won’t have to wait for the answer to you question on a public forum and rely on the kindness of hopefully reliable strangers.

Rule of thumb may be: has it been done a million times before? Find a good tutorial. Is this something I’ve never seen before or can’t I find a good tutorial about this? Ask around.