Skip to content

Commit

Permalink
Align air navmesh params to agent params, #9
Browse files Browse the repository at this point in the history
  • Loading branch information
Scony committed Dec 10, 2023
1 parent 9f78c60 commit c29ebfd
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
28 changes: 28 additions & 0 deletions source/match/AirNavigation.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ extends Node3D


func _ready():
assert(_safety_checks())
NavigationServer3D.map_set_cell_size(navigation_map_rid, Constants.Match.Air.Navmesh.CELL_SIZE)
NavigationServer3D.map_set_cell_height(
navigation_map_rid, Constants.Match.Air.Navmesh.CELL_HEIGHT
)
NavigationServer3D.region_set_map(_navigation_region.get_region_rid(), navigation_map_rid)
NavigationServer3D.map_force_update(navigation_map_rid)
NavigationServer3D.map_set_active(navigation_map_rid, true)
Expand All @@ -17,3 +22,26 @@ func _ready():
func rebake(map):
find_child("ReferenceMesh").mesh = map.find_child("Terrain").mesh
_navigation_region.bake_navigation_mesh(false)


func _safety_checks():
assert(
is_equal_approx(
_navigation_region.navigation_mesh.agent_radius,
Constants.Match.Air.Navmesh.MAX_AGENT_RADIUS
),
"Navmesh 'agent_radius' must match established constant"
)
assert(
is_equal_approx(
_navigation_region.navigation_mesh.cell_size, Constants.Match.Air.Navmesh.CELL_SIZE
),
"Navmesh 'cell_size' must match established constant"
)
assert(
is_equal_approx(
_navigation_region.navigation_mesh.cell_height, Constants.Match.Air.Navmesh.CELL_HEIGHT
),
"Navmesh 'cell_height' must match established constant"
)
return true
9 changes: 7 additions & 2 deletions source/match/Match.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,15 @@ size = Vector2(50, 50)
center_offset = Vector3(25, 0, 25)

[sub_resource type="NavigationMesh" id="NavigationMesh_8emvl"]
vertices = PackedVector3Array(6.5, 2, 0.5, 0.5, 2, 0.5, 0.5, 2, 6.5, 0.5, 2, 43.25, 0.5, 2, 49.5, 6.5, 2, 49.5, 49.5, 2, 6.5, 49.5, 2, 0.5, 43.25, 2, 0.5, 43.25, 2, 49.5, 49.5, 2, 49.5, 49.5, 2, 43.25, 0.5, 2, 37.25, 0.5, 2, 43.25, 6.5, 2, 49.5, 12.75, 2, 49.5, 49.5, 2, 6.5, 43.25, 2, 0.5, 37.25, 2, 0.5, 49.5, 2, 12.75, 12.75, 2, 0.5, 6.5, 2, 0.5, 0.5, 2, 6.5, 0.5, 2, 12.75, 37.25, 2, 49.5, 43.25, 2, 49.5, 49.5, 2, 43.25, 31, 2, 49.5, 49.5, 2, 37.25, 49.5, 2, 31, 25, 2, 49.5, 37.25, 2, 49.5, 49.5, 2, 43.25, 49.5, 2, 37.25, 31, 2, 49.5, 25, 2, 0.5, 18.75, 2, 0.5, 0.5, 2, 18.75, 0.5, 2, 25, 49.5, 2, 25, 25, 2, 0.5, 0.5, 2, 25, 18.75, 2, 49.5, 25, 2, 49.5, 49.5, 2, 31, 0.5, 2, 37.25, 12.75, 2, 49.5, 18.75, 2, 49.5, 0.5, 2, 31, 49.5, 2, 18.75, 49.5, 2, 12.75, 37.25, 2, 0.5, 31, 2, 0.5, 18.75, 2, 0.5, 12.75, 2, 0.5, 0.5, 2, 12.75, 0.5, 2, 18.75, 0.5, 2, 25, 0.5, 2, 31, 18.75, 2, 49.5, 49.5, 2, 18.75, 31, 2, 0.5, 25, 2, 0.5, 49.5, 2, 25)
polygons = [PackedInt32Array(2, 1, 0), PackedInt32Array(5, 4, 3), PackedInt32Array(8, 7, 6), PackedInt32Array(11, 10, 9), PackedInt32Array(13, 12, 14), PackedInt32Array(14, 12, 15), PackedInt32Array(17, 16, 18), PackedInt32Array(18, 16, 19), PackedInt32Array(21, 20, 22), PackedInt32Array(22, 20, 23), PackedInt32Array(26, 25, 24), PackedInt32Array(28, 27, 29), PackedInt32Array(29, 27, 30), PackedInt32Array(32, 31, 33), PackedInt32Array(33, 31, 34), PackedInt32Array(36, 35, 37), PackedInt32Array(37, 35, 38), PackedInt32Array(44, 43, 39), PackedInt32Array(39, 43, 42), PackedInt32Array(39, 42, 41), PackedInt32Array(39, 41, 40), PackedInt32Array(46, 45, 47), PackedInt32Array(47, 45, 48), PackedInt32Array(50, 49, 51), PackedInt32Array(51, 49, 52), PackedInt32Array(54, 53, 55), PackedInt32Array(55, 53, 56), PackedInt32Array(59, 58, 57), PackedInt32Array(61, 60, 62), PackedInt32Array(62, 60, 63)]
vertices = PackedVector3Array(0.8, 2.3, 0.8, 0.8, 2.3, 49.2, 49.2, 2.3, 49.2, 49.2, 2.3, 0.8)
polygons = [PackedInt32Array(3, 2, 0), PackedInt32Array(0, 2, 1)]
geometry_source_geometry_mode = 2
geometry_source_group_name = &"air_navigation_input"
cell_size = 0.4
cell_height = 0.4
agent_height = 2.0
agent_radius = 0.8
agent_max_climb = 0.0

[sub_resource type="NavigationMesh" id="NavigationMesh_exfwj"]
vertices = PackedVector3Array(6.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 6.5, 0.5, 0.5, 43.25, 0.5, 0.5, 49.5, 6.5, 0.5, 49.5, 49.5, 0.5, 6.5, 49.5, 0.5, 0.5, 43.25, 0.5, 0.5, 43.25, 0.5, 49.5, 49.5, 0.5, 49.5, 49.5, 0.5, 43.25, 0.5, 0.5, 37.25, 0.5, 0.5, 43.25, 6.5, 0.5, 49.5, 12.75, 0.5, 49.5, 49.5, 0.5, 6.5, 43.25, 0.5, 0.5, 37.25, 0.5, 0.5, 49.5, 0.5, 12.75, 12.75, 0.5, 0.5, 6.5, 0.5, 0.5, 0.5, 0.5, 6.5, 0.5, 0.5, 12.75, 37.25, 0.5, 49.5, 43.25, 0.5, 49.5, 49.5, 0.5, 43.25, 31, 0.5, 49.5, 49.5, 0.5, 37.25, 49.5, 0.5, 31, 25, 0.5, 49.5, 37.25, 0.5, 49.5, 49.5, 0.5, 43.25, 49.5, 0.5, 37.25, 31, 0.5, 49.5, 25, 0.5, 0.5, 18.75, 0.5, 0.5, 0.5, 0.5, 18.75, 0.5, 0.5, 25, 49.5, 0.5, 25, 25, 0.5, 0.5, 0.5, 0.5, 25, 18.75, 0.5, 49.5, 25, 0.5, 49.5, 49.5, 0.5, 31, 0.5, 0.5, 37.25, 12.75, 0.5, 49.5, 18.75, 0.5, 49.5, 0.5, 0.5, 31, 49.5, 0.5, 18.75, 49.5, 0.5, 12.75, 37.25, 0.5, 0.5, 31, 0.5, 0.5, 18.75, 0.5, 0.5, 12.75, 0.5, 0.5, 0.5, 0.5, 12.75, 0.5, 0.5, 18.75, 0.5, 0.5, 25, 0.5, 0.5, 31, 18.75, 0.5, 49.5, 49.5, 0.5, 18.75, 31, 0.5, 0.5, 25, 0.5, 0.5, 49.5, 0.5, 25)
Expand Down
5 changes: 5 additions & 0 deletions source/match/MatchConstants.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class Air:
const Y = 1.5
const PLANE = Plane(Vector3.UP, Y)

class Navmesh:
const CELL_SIZE = 0.4
const CELL_HEIGHT = 0.4
const MAX_AGENT_RADIUS = 0.8


class Terrain:
const PLANE = Plane(Vector3.UP, 0)
Expand Down
13 changes: 13 additions & 0 deletions source/match/units/Unit.gd
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func _ready():
if player == null:
await _match.ready
_setup_default_properties_from_constants()
assert(_safety_checks())


func is_revealing():
Expand Down Expand Up @@ -121,6 +122,18 @@ func _teardown_current_action():
remove_child(action) # triggers _on_action_node_tree_exited immediately


func _safety_checks():
if movement_domain == Constants.Match.Navigation.Domain.AIR:
assert(
(
radius < Constants.Match.Air.Navmesh.MAX_AGENT_RADIUS
or is_equal_approx(radius, Constants.Match.Air.Navmesh.MAX_AGENT_RADIUS)
),
"Unit radius exceeds the established limit"
)
return true


func _handle_unit_death():
tree_exited.connect(func(): MatchSignals.unit_died.emit(self))
queue_free()
Expand Down

0 comments on commit c29ebfd

Please sign in to comment.