Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Navigation #100

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion source/match/Match.gd
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@ func _enter_tree():

func _ready():
MatchSignals.setup_and_spawn_unit.connect(_setup_and_spawn_unit)
MatchSignals.unit_died.connect(_on_unit_died)
MatchSignals.resource_depleted.connect(_on_resource_depleted)
_setup_subsystems_dependent_on_map()
_setup_players()
_setup_player_units()
visible_player = get_tree().get_nodes_in_group("players")[settings.visible_player]
_move_camera_to_initial_position()
if settings.visibility == settings.Visibility.FULL:
fog_of_war.reveal()
await get_tree().process_frame
navigation.update_terrain()


func _unhandled_input(event):
Expand Down Expand Up @@ -126,7 +130,6 @@ func _setup_player_units():
player, map.find_child("SpawnPoints").get_child(player_index).global_transform
)


func _spawn_player_units(player, spawn_transform):
_setup_and_spawn_unit(CommandCenter.instantiate(), spawn_transform, player, false)
_setup_and_spawn_unit(
Expand All @@ -146,6 +149,8 @@ func _setup_and_spawn_unit(unit, a_transform, player, mark_structure_under_const
unit.mark_as_under_construction()
_setup_unit_groups(unit, player)
player.add_child(unit)
if unit is Structure and mark_structure_under_construction:
navigation.update_terrain()
MatchSignals.unit_spawned.emit(unit)


Expand Down Expand Up @@ -202,3 +207,10 @@ func _conceal_player_units(player):
func(a_unit): return a_unit.player == player
):
unit.remove_from_group("revealed_units")

func _on_unit_died(unit):
if unit is Structure:
navigation.update_terrain()

func _on_resource_depleted():
navigation.update_terrain()
5 changes: 3 additions & 2 deletions source/match/Match.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
[ext_resource type="PackedScene" uid="uid://bocb7hjilvri5" path="res://source/match/handlers/ArealUnitSelectionHandler.tscn" id="24_aug7m"]
[ext_resource type="PackedScene" uid="uid://pi813oou7xim" path="res://source/match/handlers/DoubleClickUnitSelectionHandler.tscn" id="25_ldkhw"]
[ext_resource type="PackedScene" uid="uid://yn470qvc3eak" path="res://source/match/handlers/MatchEndHandler.tscn" id="26_4d7im"]
[ext_resource type="PackedScene" path="res://source/match/handlers/UnitGroupSelectionHandler.tscn" id="27_j2drv"]
[ext_resource type="PackedScene" uid="uid://ck6vrgdyg7hja" path="res://source/match/handlers/UnitGroupSelectionHandler.tscn" id="27_j2drv"]
[ext_resource type="PackedScene" uid="uid://b8p6lcwubx1tp" path="res://source/match/handlers/UnitVisibilityHandler.tscn" id="32_fci1c"]

[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_ysb0j"]
Expand Down Expand Up @@ -101,8 +101,9 @@ geometry_parsed_geometry_type = 2
geometry_collision_mask = 4278190082
geometry_source_geometry_mode = 2
geometry_source_group_name = &"terrain_navigation_input"
cell_size = 0.2
agent_height = 2.0
agent_radius = 1.0
agent_radius = 0.6
agent_max_climb = 0.0

[sub_resource type="ViewportTexture" id="ViewportTexture_vu2gm"]
Expand Down
4 changes: 2 additions & 2 deletions source/match/MatchConstants.gd
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class Terrain:
const PLANE = Plane(Vector3.UP, 0)

class Navmesh:
const CELL_SIZE = 0.25
const CELL_SIZE = 0.2
const CELL_HEIGHT = 0.25
const MAX_AGENT_RADIUS = 1.0 # max radius of movable units
const MAX_AGENT_RADIUS = 0.6 # max radius of movable units


class Resources:
Expand Down
1 change: 1 addition & 0 deletions source/match/MatchSignals.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ signal unit_targeted(unit)
signal unit_selected(unit)
signal unit_deselected(unit)
signal unit_died(unit)
signal resource_depleted()
12 changes: 10 additions & 2 deletions source/match/Navigation.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,19 @@ func get_navigation_map_rid_by_domain(domain):


func rebake(map):
var obstacles = get_tree().get_nodes_in_group("terrain_navigation_input")
for obstacle in obstacles:
if obstacle.name.to_lower() != "terrain":
obstacle.remove_from_group("terrain_navigation_input")
air.rebake(map)
terrain.rebake()
terrain.rebake(false)
for obstacle in obstacles:
obstacle.add_to_group("terrain_navigation_input")
_clear_static_obstacles()
_setup_static_obstacles()


func update_terrain():
terrain.rebake(true)

func _clear_static_obstacles():
for static_obstacle in _static_obstacles:
Expand Down
4 changes: 2 additions & 2 deletions source/match/TerrainNavigation.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ func _ready():
NavigationServer3D.map_force_update(navigation_map_rid)


func rebake():
_navigation_region.bake_navigation_mesh(false)
func rebake(on_thread:bool):
_navigation_region.bake_navigation_mesh(on_thread)


func _safety_checks():
Expand Down
11 changes: 10 additions & 1 deletion source/match/units/AircraftFactory.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=11 format=3 uid="uid://cxilu6668nda6"]
[gd_scene load_steps=12 format=3 uid="uid://cxilu6668nda6"]

[ext_resource type="Script" path="res://source/match/units/AircraftFactory.gd" id="1_n6n1v"]
[ext_resource type="PackedScene" uid="uid://cgsi062w5fjia" path="res://source/match/units/traits/Highlight.tscn" id="1_r5i7t"]
Expand All @@ -14,6 +14,9 @@
height = 1.0
radius = 1.5

[sub_resource type="BoxMesh" id="BoxMesh_oki0p"]
size = Vector3(2, 1, 2)

[node name="AircraftFactory" type="Area3D"]
collision_layer = 2
collision_mask = 0
Expand Down Expand Up @@ -49,4 +52,10 @@ radius = 1.5

[node name="ProductionQueue" parent="." instance=ExtResource("9_c3qd5")]

[node name="NavMeshObstacle" type="MeshInstance3D" parent="." groups=["terrain_navigation_input"]]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
layers = 0
mesh = SubResource("BoxMesh_oki0p")
skeleton = NodePath("../CollisionShape3D")

[editable path="Geometry"]
13 changes: 12 additions & 1 deletion source/match/units/AntiAirTurret.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=10 format=3 uid="uid://cfa8cpnpk5pcb"]
[gd_scene load_steps=11 format=3 uid="uid://cfa8cpnpk5pcb"]

[ext_resource type="Script" path="res://source/match/units/AntiAirTurret.gd" id="1_ec2s5"]
[ext_resource type="PackedScene" uid="uid://cgsi062w5fjia" path="res://source/match/units/traits/Highlight.tscn" id="1_tbjvv"]
Expand All @@ -13,6 +13,11 @@
height = 0.8
radius = 0.6

[sub_resource type="CylinderMesh" id="CylinderMesh_v80fm"]
top_radius = 0.6
bottom_radius = 0.6
height = 0.8

[node name="AntiAirTurret" type="Area3D"]
collision_layer = 2
collision_mask = 0
Expand Down Expand Up @@ -68,5 +73,11 @@ radius = 0.6
[node name="RotateRandomlyWhenLookingForTargetsIdle" parent="." instance=ExtResource("8_hqxqv")]
node_to_rotate = NodePath("../DetachTransform/Geometry/turret_double/tmpParent/turret_double2/turret")

[node name="NavMeshObstacle" type="MeshInstance3D" parent="." groups=["terrain_navigation_input"]]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.4, 0)
layers = 0
mesh = SubResource("CylinderMesh_v80fm")
skeleton = NodePath("../CollisionShape3D")

[editable path="DetachTransform/Geometry"]
[editable path="DetachTransform/Geometry/turret_double"]
13 changes: 12 additions & 1 deletion source/match/units/AntiGroundTurret.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=10 format=3 uid="uid://b8pckq1xn44ss"]
[gd_scene load_steps=11 format=3 uid="uid://b8pckq1xn44ss"]

[ext_resource type="PackedScene" uid="uid://cgsi062w5fjia" path="res://source/match/units/traits/Highlight.tscn" id="1_5gp2d"]
[ext_resource type="Script" path="res://source/match/units/AntiGroundTurret.gd" id="1_6hw4x"]
Expand All @@ -13,6 +13,11 @@
height = 0.8
radius = 0.6

[sub_resource type="CylinderMesh" id="CylinderMesh_ymrt0"]
top_radius = 0.6
bottom_radius = 0.6
height = 0.8

[node name="AntiGroundTurret" type="Area3D"]
collision_layer = 2
collision_mask = 0
Expand Down Expand Up @@ -62,5 +67,11 @@ radius = 0.6
[node name="RotateRandomlyWhenLookingForTargets" parent="." instance=ExtResource("8_l7mop")]
node_to_rotate = NodePath("../DetachTransform/Geometry/turret_single/tmpParent/turret_single2/turret")

[node name="NavMeshObstacle" type="MeshInstance3D" parent="." groups=["terrain_navigation_input"]]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.4, 0)
layers = 0
mesh = SubResource("CylinderMesh_ymrt0")
skeleton = NodePath("../CollisionShape3D")

[editable path="DetachTransform/Geometry"]
[editable path="DetachTransform/Geometry/turret_single"]
12 changes: 11 additions & 1 deletion source/match/units/CommandCenter.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=11 format=3 uid="uid://ct0ejt0trkhrf"]
[gd_scene load_steps=12 format=3 uid="uid://ct0ejt0trkhrf"]

[ext_resource type="Script" path="res://source/match/units/CommandCenter.gd" id="1_hpo2s"]
[ext_resource type="PackedScene" uid="uid://cgsi062w5fjia" path="res://source/match/units/traits/Highlight.tscn" id="2_c41i5"]
Expand All @@ -14,6 +14,11 @@
height = 0.8
radius = 1.8

[sub_resource type="CylinderMesh" id="CylinderMesh_tf5as"]
top_radius = 1.8
bottom_radius = 1.8
height = 0.8

[node name="CommandCenter" type="Area3D"]
collision_layer = 2
collision_mask = 0
Expand Down Expand Up @@ -49,4 +54,9 @@ radius = 2.0

[node name="ProductionQueue" parent="." instance=ExtResource("9_y6bg8")]

[node name="NavMeshObstacle" type="MeshInstance3D" parent="." groups=["terrain_navigation_input"]]
transform = Transform3D(0.707107, 0, 0.707107, 0, 1, 0, -0.707107, 0, 0.707107, 0, 0.4, 0)
layers = 0
mesh = SubResource("CylinderMesh_tf5as")

[editable path="Geometry"]
4 changes: 2 additions & 2 deletions source/match/units/Tank.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

[sub_resource type="CylinderShape3D" id="CylinderShape3D_sjc11"]
height = 0.6
radius = 0.8
radius = 0.6

[node name="Tank" type="Area3D"]
collision_layer = 2
Expand Down Expand Up @@ -45,7 +45,7 @@ path_desired_distance = 0.5
target_desired_distance = 0.5
path_height_offset = 0.5
path_max_distance = 0.51
radius = 1.0
radius = 0.6
neighbor_distance = 8.0
max_neighbors = 40
time_horizon_agents = 3.0
Expand Down
13 changes: 12 additions & 1 deletion source/match/units/VehicleFactory.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=11 format=3 uid="uid://h5lqor1xl2sf"]
[gd_scene load_steps=12 format=3 uid="uid://h5lqor1xl2sf"]

[ext_resource type="Script" path="res://source/match/units/VehicleFactory.gd" id="1_1a20j"]
[ext_resource type="PackedScene" uid="uid://cgsi062w5fjia" path="res://source/match/units/traits/Highlight.tscn" id="1_8fcgb"]
Expand All @@ -14,6 +14,11 @@
height = 1.0
radius = 1.5

[sub_resource type="CylinderMesh" id="CylinderMesh_nlnof"]
top_radius = 1.5
bottom_radius = 1.5
height = 1.0

[node name="VehicleFactory" type="Area3D"]
collision_layer = 2
collision_mask = 0
Expand Down Expand Up @@ -49,4 +54,10 @@ radius = 1.5

[node name="ProductionQueue" parent="." instance=ExtResource("9_3s532")]

[node name="NavMeshObstacle" type="MeshInstance3D" parent="." groups=["terrain_navigation_input"]]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
layers = 0
mesh = SubResource("CylinderMesh_nlnof")
skeleton = NodePath("../CollisionShape3D")

[editable path="Geometry"]
1 change: 1 addition & 0 deletions source/match/units/non-player/ResourceA.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const MATERIAL_ALBEDO_TO_REPLACE_EPSILON = 0.05
set(value):
resource_a = max(0, value)
if resource_a == 0:
tree_exited.connect(func(): MatchSignals.resource_depleted.emit())
queue_free()

var color = Constants.Match.Resources.A.COLOR:
Expand Down
13 changes: 12 additions & 1 deletion source/match/units/non-player/ResourceA.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=8 format=3 uid="uid://bf3jjdafqvh0w"]
[gd_scene load_steps=9 format=3 uid="uid://bf3jjdafqvh0w"]

[ext_resource type="Script" path="res://source/match/units/non-player/ResourceA.gd" id="1_3daqx"]
[ext_resource type="PackedScene" uid="uid://cgsi062w5fjia" path="res://source/match/units/traits/Highlight.tscn" id="1_d3pi2"]
Expand All @@ -10,6 +10,11 @@
[sub_resource type="CylinderShape3D" id="CylinderShape3D_msmnm"]
height = 0.6

[sub_resource type="CylinderMesh" id="CylinderMesh_ep7dh"]
top_radius = 0.4
bottom_radius = 0.4
height = 1.0

[node name="ResourceA" type="Area3D" groups=["resource_units"]]
script = ExtResource("1_3daqx")

Expand Down Expand Up @@ -37,3 +42,9 @@ path_height_offset = 0.5
[node name="Targetability" parent="." instance=ExtResource("5_vqxvf")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.05, 0)
radius = 0.6

[node name="NavMeshObstacle" type="MeshInstance3D" parent="." groups=["terrain_navigation_input"]]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
layers = 0
mesh = SubResource("CylinderMesh_ep7dh")
skeleton = NodePath("../CollisionShape3D")
1 change: 1 addition & 0 deletions source/match/units/non-player/ResourceB.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const MATERIAL_ALBEDO_TO_REPLACE_EPSILON = 0.05
set(value):
resource_b = max(0, value)
if resource_b == 0:
tree_exited.connect(func(): MatchSignals.resource_depleted.emit())
queue_free()

var color = Constants.Match.Resources.B.COLOR:
Expand Down
13 changes: 12 additions & 1 deletion source/match/units/non-player/ResourceB.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=8 format=3 uid="uid://bufgjfa3ne3uk"]
[gd_scene load_steps=9 format=3 uid="uid://bufgjfa3ne3uk"]

[ext_resource type="Script" path="res://source/match/units/non-player/ResourceB.gd" id="1_57n8v"]
[ext_resource type="PackedScene" uid="uid://cgsi062w5fjia" path="res://source/match/units/traits/Highlight.tscn" id="2_c8mwe"]
Expand All @@ -10,6 +10,11 @@
[sub_resource type="CylinderShape3D" id="CylinderShape3D_msmnm"]
height = 0.8

[sub_resource type="CylinderMesh" id="CylinderMesh_ajrhd"]
top_radius = 0.4
bottom_radius = 0.4
height = 1.0

[node name="ResourceB" type="Area3D" groups=["resource_units"]]
script = ExtResource("1_57n8v")

Expand Down Expand Up @@ -37,3 +42,9 @@ path_height_offset = 0.5
[node name="Targetability" parent="." instance=ExtResource("5_y6273")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.05, 0)
radius = 0.6

[node name="NavMeshObstacle" type="MeshInstance3D" parent="." groups=["terrain_navigation_input"]]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
layers = 0
mesh = SubResource("CylinderMesh_ajrhd")
skeleton = NodePath("../CollisionShape3D")
8 changes: 5 additions & 3 deletions source/match/utils/UnitPlacementUtils.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
enum { VALID, COLLIDES_WITH_AGENT, NOT_NAVIGABLE }

const epsilon = 0.05 # Custom approximation variable check for terrain


static func find_valid_position_radially(
starting_position: Vector3, radius: float, navigation_map_rid: RID, scene_tree
Expand Down Expand Up @@ -79,14 +81,14 @@ static func validate_agent_placement_position(position, radius, existing_units,
position + Vector3(x, 0, z).normalized() * radius
)
for point_expected_to_be_navigable in points_expected_to_be_navigable:
if not (point_expected_to_be_navigable * Vector3(1, 0, 1)).is_equal_approx(
if not (point_expected_to_be_navigable * Vector3(1, 0, 1)).distance_to(
(
NavigationServer3D.map_get_closest_point(
navigation_map_rid, point_expected_to_be_navigable
)
* Vector3(1, 0, 1)
)
):
)
) < epsilon :
return NOT_NAVIGABLE
return VALID

Expand Down
Loading