Skip to content

Commit

Permalink
Use static collider for air navigation reference instead of mesh
Browse files Browse the repository at this point in the history
  • Loading branch information
Scony committed Aug 25, 2024
1 parent 556fd83 commit 50c1cea
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,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"
3d_physics/layer_4="Air"

[navigation]

Expand Down
13 changes: 7 additions & 6 deletions source/match/AirNavigation.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extends Node3D
@onready var navigation_map_rid = NavigationServer3D.map_create()

@onready var _navigation_region = find_child("NavigationRegion3D")
@onready var _reference_mesh = find_child("ReferenceMesh")
@onready var _reference_static_collider_shape = find_child("CollisionShape3D")


func _ready():
Expand All @@ -16,18 +16,19 @@ func _ready():
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)
_reference_mesh.global_transform.origin.y = Constants.Match.Air.Y
_reference_static_collider_shape.global_transform.origin.y = Constants.Match.Air.Y


func bake(map):
assert(
_navigation_region.navigation_mesh.get_polygon_count() == 0,
"bake() should be called exactly once - during runtime"
)
var plane_mesh = PlaneMesh.new()
plane_mesh.size = map.size
plane_mesh.center_offset = Vector3(map.size.x, 0, map.size.y) / 2.0
_reference_mesh.mesh = plane_mesh
var shape = BoxShape3D.new()
shape.size = Vector3(map.size.x, 0, map.size.y)
_reference_static_collider_shape.shape = shape
_reference_static_collider_shape.global_transform.origin.x = map.size.x / 2.0
_reference_static_collider_shape.global_transform.origin.z = map.size.y / 2.0
_navigation_region.bake_navigation_mesh(false)


Expand Down
13 changes: 10 additions & 3 deletions source/match/Match.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ flip_faces = true
size = Vector2(2, 2)

[sub_resource type="NavigationMesh" id="NavigationMesh_8emvl"]
geometry_source_geometry_mode = 2
geometry_parsed_geometry_type = 1
geometry_collision_mask = 4278190088
geometry_source_geometry_mode = 1
geometry_source_group_name = &"air_navigation_input"
cell_size = 0.4
cell_height = 0.4
Expand Down Expand Up @@ -220,9 +222,14 @@ script = ExtResource("10_1wfp1")
[node name="Air" type="Node3D" parent="Navigation"]
script = ExtResource("16_ravsv")

[node name="ReferenceMesh" type="MeshInstance3D" parent="Navigation/Air" groups=["air_navigation_input"]]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, 0)
[node name="ReferenceStaticCollider" type="StaticBody3D" parent="Navigation/Air" groups=["air_navigation_input"]]
visible = false
collision_layer = 8
collision_mask = 0
input_ray_pickable = false

[node name="CollisionShape3D" type="CollisionShape3D" parent="Navigation/Air/ReferenceStaticCollider"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, 0)

[node name="NavigationRegion3D" type="NavigationRegion3D" parent="Navigation/Air"]
navigation_mesh = SubResource("NavigationMesh_8emvl")
Expand Down

0 comments on commit 50c1cea

Please sign in to comment.