fuzzyworld

godot-shooter / commit

Got navigation working, but with caveats:

de59c0517b6a282d23170664321534384924e51b · Pavel Safronov · 2023-11-30 11:26:07 -0800 · parents 3e350e62578a

Got navigation working, but with caveats:
- Needed to add a big NavigationPolygonInstance to world scene, and this determines where the enemies can travel. This needs to be either an infinite polygon, or it has to be adjusted in real-time, or something.
- the enemies aren't avoiding each other yet
 actors/Enemy.tscn | 17 +++++------------
 scenes/World.gd   |  2 +-
 scenes/World.tscn |  8 +++++++-
 3 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/actors/Enemy.tscn b/actors/Enemy.tscn
index c39e83f..390be18 100644
--- a/actors/Enemy.tscn
+++ b/actors/Enemy.tscn
@@ -1,4 +1,4 @@
-[gd_scene load_steps=12 format=2]
+[gd_scene load_steps=11 format=2]
 
 [ext_resource path="res://effects/Trails.tscn" type="PackedScene" id=2]
 [ext_resource path="res://actors/Enemy.gd" type="Script" id=3]
@@ -86,11 +86,6 @@ tracks/2/keys = {
 "values": [ 1.0, 0.0 ]
 }
 
-[sub_resource type="NavigationPolygon" id=7]
-vertices = PoolVector2Array( -39, -40, 41, -41, 41, 41, -41, 39 )
-polygons = [ PoolIntArray( 0, 1, 2, 3 ) ]
-outlines = [ PoolVector2Array( -39, -40, 41, -41, 41, 41, -41, 39 ) ]
-
 [node name="Enemy" type="KinematicBody2D"]
 z_index = 10
 collision_layer = 2
@@ -148,15 +143,13 @@ enabled = true
 cast_to = Vector2( 0, -50 )
 
 [node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."]
-visible = false
 polygon = PoolVector2Array( 0, -23, -7, 5, -12, 9, -19, 9, -23, 14, -23, 19, -19, 23, -14, 23, -9, 19, -9, 14, -10, 12, -6, 9, 0, 15, 6, 9, 10, 12, 9, 14, 9, 19, 13, 23, 18, 23, 23, 18, 23, 14, 19, 10, 13, 10, 7, 5 )
 
 [node name="DamageObjects" type="Node2D" parent="."]
 
-[node name="NavigationPolygonInstance" type="NavigationPolygonInstance" parent="."]
-navpoly = SubResource( 7 )
-
 [node name="NavigationAgent2D" type="NavigationAgent2D" parent="."]
+path_desired_distance = 100.0
+target_desired_distance = 10.0
+avoidance_enabled = true
+radius = 100.0
 max_speed = 100.0
-
-[node name="NavigationObstacle2D" type="NavigationObstacle2D" parent="."]
diff --git a/scenes/World.gd b/scenes/World.gd
index 44eeb39..ba73d04 100644
--- a/scenes/World.gd
+++ b/scenes/World.gd
@@ -11,7 +11,7 @@ onready var player: Player = $Player
 onready var update_timer = $UpdateTimer
 
 var generators = [
-	ConstantItemGenerator.new("create_enemy", self, "enemies", 2),
+	ConstantItemGenerator.new("create_enemy", self, "enemies", 5),
 	ConstantItemGenerator.new("create_health", self, "health", 10),
 	ConstantItemGenerator.new("create_weapon", self, "weapon", 10),
 	ConstantItemGenerator.new("create_bomb", self, "bombs", 10),
diff --git a/scenes/World.tscn b/scenes/World.tscn
index dcd0cf3..ba2b7f4 100644
--- a/scenes/World.tscn
+++ b/scenes/World.tscn
@@ -1,4 +1,4 @@
-[gd_scene load_steps=6 format=2]
+[gd_scene load_steps=7 format=2]
 
 [ext_resource path="res://assets/kenney_simple-space/PNG/Default/icon_crossLarge.png" type="Texture" id=1]
 [ext_resource path="res://actors/Player.tscn" type="PackedScene" id=2]
@@ -8,6 +8,11 @@
 [sub_resource type="CircleShape2D" id=1]
 radius = 29.0172
 
+[sub_resource type="NavigationPolygon" id=2]
+vertices = PoolVector2Array( -2942, -2484, 5873, -3309, 5048, 4696, -3090, 5040 )
+polygons = [ PoolIntArray( 0, 1, 2, 3 ) ]
+outlines = [ PoolVector2Array( -2942, -2484, 5873, -3309, 5048, 4696, -3090, 5040 ) ]
+
 [node name="World" type="Node2D"]
 script = ExtResource( 4 )
 
@@ -77,6 +82,7 @@ wait_time = 0.1
 autostart = true
 
 [node name="NavigationPolygonInstance" type="NavigationPolygonInstance" parent="."]
+navpoly = SubResource( 2 )
 
 [connection signal="body_entered" from="Destination" to="." method="_on_Destination_body_entered"]
 [connection signal="debug" from="Player" to="." method="_on_Player_debug"]