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!
