35 lines
1.1 KiB
GDScript
35 lines
1.1 KiB
GDScript
extends Node
|
|
|
|
@export var prompt: Node
|
|
@export var player: Player
|
|
@export var grabbable_finder: RayCast3D
|
|
|
|
var action_panel_body = null
|
|
|
|
func handle_body(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")
|
|
elif body is Button3D:
|
|
prompt.change_text("[R] to use")
|
|
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 hide_prompt() -> void:
|
|
action_panel_body = null
|
|
prompt.visible = false
|
|
|
|
func _process(delta: float) -> void:
|
|
if grabbable_finder.get_collider():
|
|
var body = grabbable_finder.get_collider()
|
|
handle_body(body)
|
|
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)
|
|
else:
|
|
hide_prompt()
|