33 lines
882 B
GDScript3
33 lines
882 B
GDScript3
|
extends Node3D
|
||
|
class_name Entity
|
||
|
|
||
|
|
||
|
## Base entity class for everything interactive.
|
||
|
##
|
||
|
## Should be the parent of every units, buildings,
|
||
|
## npc, loot, and everything that the player can interact with in 3D
|
||
|
|
||
|
|
||
|
func _ready() -> void:
|
||
|
add_to_group('selectable')
|
||
|
|
||
|
|
||
|
## Check if the entity is contained in the [Rect2] [param selection_box] of the player.
|
||
|
## Need the [Camera3D] of the player to work
|
||
|
func is_in_selection(selection_box:Rect2,player_cam:Camera3D):
|
||
|
var p = player_cam.unproject_position(global_position)
|
||
|
if min(selection_box.size.x,selection_box.size.y) <0:
|
||
|
breakpoint
|
||
|
|
||
|
return selection_box.has_point(p)
|
||
|
|
||
|
|
||
|
func select():
|
||
|
add_to_group('selected-by-'+str(get_tree().get_multiplayer().get_unique_id()))
|
||
|
print(self.name," selected")
|
||
|
|
||
|
|
||
|
func deselect():
|
||
|
remove_from_group('selected-by-'+str(get_tree().get_multiplayer().get_unique_id()))
|
||
|
print(self.name," unselected")
|