basic pathfinding for dudes

This commit is contained in:
Vivianne 2023-10-06 03:36:57 -07:00
parent 56bcfcf667
commit 2831f9620e
4 changed files with 62 additions and 3 deletions

View file

@ -13,7 +13,8 @@
[sub_resource type="CircleShape2D" id="CircleShape2D_tt36q"]
radius = 31.3847
[node name="BadDude" type="RigidBody2D"]
[node name="BadDude" type="CharacterBody2D"]
motion_mode = 1
script = ExtResource("1_1wbea")
[node name="BeehaveTree" type="Node" parent="."]
@ -93,3 +94,10 @@ polygon = PackedVector2Array(12, -12, 96, -59, 96, 60, 12, 11)
[node name="EyesShape" type="Polygon2D" parent="."]
color = Color(0.929412, 1, 0.458824, 0.239216)
polygon = PackedVector2Array(32, -25, 33, 24, 269, 129, 269, -126)
[node name="Navigation" type="NavigationAgent2D" parent="."]
avoidance_enabled = true
radius = 60.0
debug_enabled = true
[connection signal="velocity_computed" from="Navigation" to="." method="_on_navigation_velocity_computed"]

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=6 format=3 uid="uid://buervcbmbh1dg"]
[gd_scene load_steps=7 format=3 uid="uid://buervcbmbh1dg"]
[ext_resource type="PackedScene" uid="uid://byuqbh3u5cxqo" path="res://bad_dude.tscn" id="2_bghxq"]
[ext_resource type="Script" path="res://hero.gd" id="3_fmhqm"]
@ -8,6 +8,11 @@
[sub_resource type="CircleShape2D" id="CircleShape2D_eiiek"]
radius = 28.7924
[sub_resource type="NavigationPolygon" id="NavigationPolygon_dxds4"]
vertices = PackedVector2Array(239, 648, 8, 648, 11, 9, 237, 164, 1147, 1, 954, 165, 1144, 638, 954, 638)
polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3), PackedInt32Array(3, 2, 4, 5), PackedInt32Array(5, 4, 6, 7)])
outlines = Array[PackedVector2Array]([PackedVector2Array(11, 9, 8, 648, 239, 648, 237, 164, 954, 165, 954, 638, 1144, 638, 1147, 1)])
[node name="Node2D" type="Node2D"]
[node name="Blackboard" type="Node" parent="."]
@ -17,6 +22,14 @@ script = ExtResource("5_6difr")
position = Vector2(77, 140)
blackboard = NodePath("../Blackboard")
[node name="BadDude3" parent="." node_paths=PackedStringArray("blackboard") instance=ExtResource("2_bghxq")]
position = Vector2(166, 441)
blackboard = NodePath("../Blackboard")
[node name="BadDude4" parent="." node_paths=PackedStringArray("blackboard") instance=ExtResource("2_bghxq")]
position = Vector2(1014, 256)
blackboard = NodePath("../Blackboard")
[node name="BadDude2" parent="." node_paths=PackedStringArray("blackboard") instance=ExtResource("2_bghxq")]
position = Vector2(788, 69)
rotation = 1.56094
@ -35,3 +48,21 @@ shape = SubResource("CircleShape2D_eiiek")
texture_filter = 1
scale = Vector2(1.21875, 1.21875)
texture = ExtResource("4_svfrs")
[node name="NavigationRegion2D" type="NavigationRegion2D" parent="."]
navigation_polygon = SubResource("NavigationPolygon_dxds4")
[node name="InterestingSpot" type="Marker2D" parent="NavigationRegion2D" groups=["InterestingSpot"]]
position = Vector2(113, 578)
[node name="InterestingSpot2" type="Marker2D" parent="NavigationRegion2D" groups=["InterestingSpot"]]
position = Vector2(128, 65)
[node name="InterestingSpot3" type="Marker2D" parent="NavigationRegion2D" groups=["InterestingSpot"]]
position = Vector2(1071, 79)
[node name="InterestingSpot4" type="Marker2D" parent="NavigationRegion2D" groups=["InterestingSpot"]]
position = Vector2(1055, 572)
[node name="InterestingSpot5" type="Marker2D" parent="NavigationRegion2D" groups=["InterestingSpot"]]
position = Vector2(570, 84)

View file

@ -1,11 +1,18 @@
class_name MeanDude
extends Node
extends CharacterBody2D
@export var blackboard: Blackboard
func _ready():
$BeehaveTree.blackboard = blackboard
go_to_interesting_spot()
func _physics_process(delta):
if not $Navigation.is_navigation_finished():
if not $Navigation.is_target_reachable():
go_to_interesting_spot()
$Navigation.velocity = position.direction_to($Navigation.get_next_path_position()) * 100
func say_shit(shit):
print(self.name, ": ", shit)
@ -13,3 +20,12 @@ func say_shit(shit):
func can_see_name(actor_name: String) -> bool:
return $Eyes.get_overlapping_bodies().any(func(b): return b.name == actor_name)
func go_to_interesting_spot() -> void:
$Navigation.target_position = get_tree().get_nodes_in_group("InterestingSpot").pick_random().position
func _on_navigation_velocity_computed(safe_velocity):
velocity = safe_velocity
move_and_slide()

View file

@ -20,6 +20,10 @@ config/icon="res://icon.svg"
BeehaveGlobalMetrics="*res://addons/beehave/metrics/beehave_global_metrics.gd"
BeehaveGlobalDebugger="*res://addons/beehave/debug/global_debugger.gd"
[editor]
movie_writer/movie_file="movie.avi"
[editor_plugins]
enabled=PackedStringArray("res://addons/beehave/plugin.cfg")