28 lines
696 B
GDScript3
28 lines
696 B
GDScript3
|
class_name VisibilityComponent
|
||
|
extends Node
|
||
|
|
||
|
@export var health: HealthComponent
|
||
|
@export var hud: HUDComponent
|
||
|
@export var physics_distance: float
|
||
|
@export var render_distance: float
|
||
|
|
||
|
var parent: Node3D
|
||
|
var main_player_distance_sq: float
|
||
|
|
||
|
func _ready():
|
||
|
parent = owner
|
||
|
physics_distance *= physics_distance
|
||
|
render_distance *= render_distance
|
||
|
update_visibility()
|
||
|
|
||
|
func update_visibility():
|
||
|
if !Global.player:
|
||
|
return
|
||
|
|
||
|
if !health.is_alive:
|
||
|
return
|
||
|
|
||
|
main_player_distance_sq = parent.global_position.distance_squared_to(Global.player.global_position)
|
||
|
parent.visible = main_player_distance_sq < render_distance
|
||
|
DeathComponent.set_physics(parent, main_player_distance_sq < physics_distance)
|