Skip to content

Commit

Permalink
Align terrain navmesh params to agent params, closes #9
Browse files Browse the repository at this point in the history
  • Loading branch information
Scony committed Dec 12, 2023
1 parent 6cb00ee commit f0c7d78
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 2 deletions.
4 changes: 4 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,7 @@ locale/translations=PackedStringArray("res://assets/translations/match.en.transl
3d_physics/layer_1="Terrain"
3d_physics/layer_2="TerrainObjects"
3d_physics/layer_3="AirObjects"

[navigation]

3d/use_edge_connections=false
7 changes: 5 additions & 2 deletions source/match/Match.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,15 @@ 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)
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(1, 0.5, 1, 1, 0.5, 49, 49, 0.5, 49, 49, 0.5, 1)
polygons = [PackedInt32Array(3, 2, 0), PackedInt32Array(0, 2, 1)]
geometry_parsed_geometry_type = 2
geometry_collision_mask = 4278190082
geometry_source_geometry_mode = 2
geometry_source_group_name = &"terrain_navigation_input"
agent_height = 2.0
agent_radius = 1.0
agent_max_climb = 0.0

[sub_resource type="ViewportTexture" id="ViewportTexture_vu2gm"]
viewport_path = NodePath("FogOfWar/CombinedViewport")
Expand Down
5 changes: 5 additions & 0 deletions source/match/MatchConstants.gd
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class Air:
class Terrain:
const PLANE = Plane(Vector3.UP, 0)

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


class Resources:
class A:
Expand Down
31 changes: 31 additions & 0 deletions source/match/TerrainNavigation.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,39 @@ extends Node3D


func _ready():
assert(_safety_checks())
NavigationServer3D.map_set_cell_size(
navigation_map_rid, Constants.Match.Terrain.Navmesh.CELL_SIZE
)
NavigationServer3D.map_set_cell_height(
navigation_map_rid, Constants.Match.Terrain.Navmesh.CELL_HEIGHT
)
NavigationServer3D.map_force_update(navigation_map_rid)


func rebake():
_navigation_region.bake_navigation_mesh(false)


func _safety_checks():
assert(
is_equal_approx(
_navigation_region.navigation_mesh.agent_radius,
Constants.Match.Terrain.Navmesh.MAX_AGENT_RADIUS
),
"Navmesh 'agent_radius' must match established constant"
)
assert(
is_equal_approx(
_navigation_region.navigation_mesh.cell_size, Constants.Match.Terrain.Navmesh.CELL_SIZE
),
"Navmesh 'cell_size' must match established constant"
)
assert(
is_equal_approx(
_navigation_region.navigation_mesh.cell_height,
Constants.Match.Terrain.Navmesh.CELL_HEIGHT
),
"Navmesh 'cell_height' must match established constant"
)
return true
15 changes: 15 additions & 0 deletions source/match/units/Unit.gd
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ func _get_movement_speed():
return 0.0


func _is_movable():
return _get_movement_speed() > 0.0


func _set_color(a_color):
color = a_color
assert(player != null, "player must be set at this point")
Expand Down Expand Up @@ -131,6 +135,17 @@ func _safety_checks():
),
"Unit radius exceeds the established limit"
)
elif movement_domain == Constants.Match.Navigation.Domain.TERRAIN:
assert(
(
not _is_movable()
or (
radius < Constants.Match.Terrain.Navmesh.MAX_AGENT_RADIUS
or is_equal_approx(radius, Constants.Match.Terrain.Navmesh.MAX_AGENT_RADIUS)
)
),
"Unit radius exceeds the established limit"
)
return true


Expand Down

0 comments on commit f0c7d78

Please sign in to comment.