28 lines
972 B
GDScript
28 lines
972 B
GDScript
extends Node
|
|
|
|
@export var prompt: Node
|
|
@export var player: Player
|
|
|
|
var action_panel_body = null
|
|
|
|
func _on_action_finder_body_entered(body: Node3D) -> void:
|
|
if body != null:
|
|
if body.is_in_group("grabbable"):
|
|
prompt.change_text("[LMB] to grab")
|
|
elif body is PickupableItem:
|
|
prompt.change_text("[R] to pick up")
|
|
else:
|
|
return
|
|
action_panel_body = body
|
|
prompt.position = -(get_viewport().get_visible_rect().size / 2 - player.camera.unproject_position(action_panel_body.global_position)) / 2
|
|
prompt.visible = true
|
|
|
|
func _on_action_finder_body_exited(body: Node3D) -> void:
|
|
if body != null and body == action_panel_body:
|
|
action_panel_body = null
|
|
prompt.visible = false
|
|
|
|
func _process(delta: float) -> void:
|
|
if action_panel_body != null:
|
|
var target_position = get_viewport().get_visible_rect().size / 2 - player.camera.unproject_position(action_panel_body.global_position)
|
|
prompt.position = prompt.position.lerp(-target_position / 2, delta * 50)
|