Hi! I’m trying to create an interactive object for my game. I created a separate scene for the interactive area, which can be “attached” to any object I want to make interactive. This component sends a signal to the UI element responsible for displaying the prompt indicating what to press, for example, [E] to open.
However, I’m having trouble positioning the Label; I need to display it above the object the player is standing next to. Objects can vary in width and height, so I need to account for that as well.
Does anyone have any suggestions on how to do this?
I’ve attached the code and scene structure below. Thanks!
class_name InteractionArea extends Area2D
@export var interaction_action_name: String = '[E] to interact'
func _on_body_entered(body: Node2D) -> void:
if body.is_in_group('player'):
EventBus.interaction_body_entered.emit(interaction_action_name)
func _on_body_exited(body: Node2D) -> void:
if body.is_in_group('player'):
EventBus.interaction_body_exited.emit()
class_name InteractionActionUI extends Control
@onready var interaction_action_label: Label = $InteractionActionLabel
func _ready() -> void:
EventBus.interaction_body_entered.connect(_on_interaction_body_entered)
EventBus.interaction_body_exited.connect(_on_interaction_body_exited)
func _on_interaction_body_entered(action_name: String) -> void:
interaction_action_label.text = action_name
interaction_action_label.show()
func _on_interaction_body_exited() -> void:
interaction_action_label.text = ''
interaction_action_label.hide()
![]()

