mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-01-19 19:44:46 +00:00
28 lines
931 B
GDScript
28 lines
931 B
GDScript
extends Node2D
|
|
|
|
@export var attach_point : Node3D
|
|
@export var player : Player
|
|
|
|
@onready var _player_name_label = $Offset/VBoxContainer/PlayerNameLabel
|
|
@onready var _health_bar = $Offset/VBoxContainer/HealthBar
|
|
@onready var _v_box_container = $Offset/VBoxContainer
|
|
|
|
func _process(_delta):
|
|
var camera : Camera3D = get_viewport().get_camera_3d()
|
|
if camera.is_position_behind(attach_point.global_position):
|
|
_v_box_container.hide()
|
|
else:
|
|
_v_box_container.show()
|
|
|
|
_player_name_label.text = player.name
|
|
position = camera.unproject_position(attach_point.global_position)
|
|
var viewport_size : Vector2 = get_viewport_rect().size
|
|
position.x = clampf(position.x, 0, viewport_size.x - _v_box_container.size.x)
|
|
position.y = clampf(position.y, _v_box_container.size.y, viewport_size.y)
|
|
|
|
func _update_health_bar(health) -> void:
|
|
_health_bar.value = health
|
|
|
|
func _on_health_changed(new_health) -> void:
|
|
_update_health_bar(new_health)
|