From c1e6d8e85e68edb13b49eed7c8b328779df88e28 Mon Sep 17 00:00:00 2001 From: lucastucious Date: Wed, 23 Jul 2025 01:16:14 +0200 Subject: [PATCH] basic selection still WIP --- core/scripts/entity.gd | 32 ++++++++++++++++++++++++++++++++ core/scripts/entity.gd.uid | 1 + 2 files changed, 33 insertions(+) create mode 100644 core/scripts/entity.gd create mode 100644 core/scripts/entity.gd.uid diff --git a/core/scripts/entity.gd b/core/scripts/entity.gd new file mode 100644 index 0000000..e9324fb --- /dev/null +++ b/core/scripts/entity.gd @@ -0,0 +1,32 @@ +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") diff --git a/core/scripts/entity.gd.uid b/core/scripts/entity.gd.uid new file mode 100644 index 0000000..d523f38 --- /dev/null +++ b/core/scripts/entity.gd.uid @@ -0,0 +1 @@ +uid://b8p60y4eo8w2n