Skip to content

Commit

Permalink
Fix air units moving out of map bounds, fixes #69
Browse files Browse the repository at this point in the history
  • Loading branch information
Scony committed Nov 13, 2023
1 parent e7c324f commit ab49385
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 26 deletions.
39 changes: 16 additions & 23 deletions source/match/Navigation.gd
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,22 @@ func _setup_static_obstacles():
for domain in [
Constants.Match.Navigation.Domain.AIR, Constants.Match.Navigation.Domain.TERRAIN
]:
for edge in [
[Vector2(0, 0), Vector2(1, 0)],
[Vector2(1, 0), Vector2(1, 1)],
[Vector2(1, 1), Vector2(0, 1)],
[Vector2(0, 1), Vector2(0, 0)],
]:
var actual_edge = [edge[0] * _match.map.size, edge[1] * _match.map.size]
var obstacle = NavigationServer3D.obstacle_create()
NavigationServer3D.obstacle_set_map(obstacle, get_navigation_map_rid_by_domain(domain))
(
NavigationServer3D
. obstacle_set_vertices(
obstacle,
[
Vector3(actual_edge[0].x, -99, actual_edge[0].y),
Vector3(actual_edge[0].x, 99, actual_edge[0].y),
Vector3(actual_edge[1].x, 99, actual_edge[1].y),
Vector3(actual_edge[1].x, -99, actual_edge[1].y),
]
)
)
NavigationServer3D.obstacle_set_avoidance_enabled(obstacle, true)
_static_obstacles.append(obstacle)
var obstacle = NavigationServer3D.obstacle_create()
NavigationServer3D.obstacle_set_map(obstacle, get_navigation_map_rid_by_domain(domain))
var obstacle_y = {
Constants.Match.Navigation.Domain.AIR: Constants.Match.Air.Y,
Constants.Match.Navigation.Domain.TERRAIN: 0,
}[domain]
NavigationServer3D.obstacle_set_position(obstacle, Vector3(0, obstacle_y, 0))
var obstacle_vertices = [
Vector3(0, 0, 0),
Vector3(0, 0, _match.map.size.y),
Vector3(_match.map.size.x, 0, _match.map.size.y),
Vector3(_match.map.size.x, 0, 0),
]
NavigationServer3D.obstacle_set_vertices(obstacle, obstacle_vertices)
NavigationServer3D.obstacle_set_avoidance_enabled(obstacle, true)
_static_obstacles.append(obstacle)


func _fix_navigation():
Expand Down
6 changes: 3 additions & 3 deletions tests/manual/TestOneUnit.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ resource_local_to_scene = true
shader = ExtResource("8_fifyq")
shader_parameter/reference_texture = SubResource("ViewportTexture_ll23y")

[sub_resource type="ViewportTexture" id="ViewportTexture_hw1xu"]
[sub_resource type="ViewportTexture" id="ViewportTexture_n2lq6"]
viewport_path = NodePath("HUD/MarginContainer/Minimap/MarginContainer/MinimapViewport")

[node name="Match" instance=ExtResource("1_fe2sx")]
Expand All @@ -67,7 +67,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 13.263, 0, 12.637)
[node name="FogOfWarMask" parent="HUD/MarginContainer/Minimap/MarginContainer/MinimapViewport" index="3"]
material = SubResource("ShaderMaterial_kdlxq")

[node name="MinimapTextureRect" parent="HUD/MarginContainer/Minimap/MarginContainer/Control" index="0"]
texture = SubResource("ViewportTexture_hw1xu")
[node name="MinimapTextureRect" parent="HUD/MarginContainer/Minimap/MarginContainer" index="1"]
texture = SubResource("ViewportTexture_n2lq6")

[editable path="Map"]

0 comments on commit ab49385

Please sign in to comment.