commit c2d3c91cf1b406828ff36cc26e336a8afb4319d8 Author: Daniel Flanagan Date: Mon Feb 5 14:40:47 2024 -0600 Initial commit diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8ad74f7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Normalize EOL for all files that Git considers text files. +* text=auto eol=lf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4709183 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Godot 4+ specific ignores +.godot/ diff --git a/icon.svg b/icon.svg new file mode 100644 index 0000000..b370ceb --- /dev/null +++ b/icon.svg @@ -0,0 +1 @@ + diff --git a/icon.svg.import b/icon.svg.import new file mode 100644 index 0000000..5315379 --- /dev/null +++ b/icon.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cmoafynkf3uu2" +path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icon.svg" +dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/project.godot b/project.godot new file mode 100644 index 0000000..229fd1e --- /dev/null +++ b/project.godot @@ -0,0 +1,16 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=5 + +[application] + +config/name="navtest" +run/main_scene="res://test.tscn" +config/features=PackedStringArray("4.2", "Forward Plus") +config/icon="res://icon.svg" diff --git a/test.gd b/test.gd new file mode 100644 index 0000000..548fcbc --- /dev/null +++ b/test.gd @@ -0,0 +1,71 @@ +extends Node2D + +const movement_speed = 100 + +var single = NavigationPolygon.new() +var double = NavigationPolygon.new() + + + + +func _ready(): + single.agent_radius = 0.75 + double.agent_radius = 1.5 + var root_node: Node3D = get_node("NavigationMeshBakingRootNode") + + NavigationServer2D.parse_source_geometry_data(single, $nav.navigation_polygon, root_node) + + for s in [single, double]: + NavigationServer2D.bake_from_source_geometry_data(single, $nav.navigation_polygon) + NavigationServer2D.bake_from_source_geometry_data(double, $nav.navigation_polygon) + + var single_map: RID = NavigationServer2D.map_create() + var double_map: RID = NavigationServer2D.map_create() + + NavigationServer2D.map_set_active(single_map, true) + NavigationServer2D.map_set_active(double_map, true) + + var single_reg: RID = NavigationServer2D.region_create() + var double_reg: RID = NavigationServer2D.region_create() + + NavigationServer2D.region_set_map(single_reg, single_map) + NavigationServer2D.region_set_map(double_reg, double_map) + + NavigationServer3D.region_set_navigation_mesh(single_reg, single) + NavigationServer3D.region_set_navigation_mesh(double_reg, double) + + $small/nav.path_desired_distance = 4.0 + $small/nav.target_desired_distance = 4.0 + $large/nav.path_desired_distance = 4.0 + $large/nav.target_desired_distance = 4.0 + + call_deferred("actor_setup") + +func actor_setup(): + print("actor_setup awaiting...") + await get_tree().physics_frame + print("actor_setup finished awaiting") + set_movement_target($target.position) + +func set_movement_target(p): + print("target: ", p) + $small/nav.target_position = p + $large/nav.target_position = p + +func _process(delta): + pass + +func do_path(a: CharacterBody2D, map: NavigationPolygon): + var n = a.get_node("nav") + if n.is_navigation_finished(): + return + var p: Vector2 = a.global_position + var path = NavigationServer2D.map_get_path(map, p, $target.global_position, true) + print(path) + a.velocity = p.direction_to(path[0]) * movement_speed + a.move_and_slide() + print(path[0]) + +func _physics_process(delta): + do_path($small, single) + do_path($large, double) diff --git a/test.tscn b/test.tscn new file mode 100644 index 0000000..c3f5f83 --- /dev/null +++ b/test.tscn @@ -0,0 +1,60 @@ +[gd_scene load_steps=5 format=3 uid="uid://c10oxh5lwghx5"] + +[ext_resource type="Texture2D" uid="uid://cmoafynkf3uu2" path="res://icon.svg" id="1_qcjqt"] +[ext_resource type="Script" path="res://test.gd" id="1_uyyrh"] + +[sub_resource type="NavigationPolygon" id="NavigationPolygon_a3hvs"] +vertices = PackedVector2Array(417, -158, 416, -158, 1288, -179, 780, 669, 1355, 828, 276, 870, 551, 669, 728, 240, 524, 250, -188, 1002, -181, -50) +polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2), PackedInt32Array(3, 4, 5, 6), PackedInt32Array(2, 4, 3, 7), PackedInt32Array(0, 2, 7, 8), PackedInt32Array(5, 9, 10, 0, 8, 6)]) +outlines = Array[PackedVector2Array]([PackedVector2Array(-201, -68, 413, -178, 1307, -200, 1377, 848, 279, 890, -209, 1029), PackedVector2Array(570, 649, 757, 649, 710, 261, 545, 269)]) +source_geometry_group_name = &"navigation_polygon_source_group" +agent_radius = 20.0 + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_mn2sd"] + +[node name="world" type="Node2D"] +position = Vector2(-1, -1) +script = ExtResource("1_uyyrh") + +[node name="nav" type="NavigationRegion2D" parent="."] +position = Vector2(-85, -45) +navigation_polygon = SubResource("NavigationPolygon_a3hvs") +metadata/_edit_lock_ = true + +[node name="small" type="CharacterBody2D" parent="."] +position = Vector2(262, 745) +motion_mode = 1 + +[node name="coll" type="CollisionShape2D" parent="small"] +scale = Vector2(6.5, 6.5) +shape = SubResource("RectangleShape2D_mn2sd") +metadata/_edit_lock_ = true + +[node name="sprite" type="Sprite2D" parent="small"] +texture = ExtResource("1_qcjqt") +metadata/_edit_lock_ = true + +[node name="nav" type="NavigationAgent2D" parent="small"] + +[node name="cam" type="Camera2D" parent="."] +offset = Vector2(200, 320) +zoom = Vector2(0.5, 0.5) + +[node name="large" type="CharacterBody2D" parent="."] +position = Vector2(29, 673) +motion_mode = 1 + +[node name="coll" type="CollisionShape2D" parent="large"] +scale = Vector2(13, 13) +shape = SubResource("RectangleShape2D_mn2sd") +metadata/_edit_lock_ = true + +[node name="sprite" type="Sprite2D" parent="large"] +scale = Vector2(2, 2) +texture = ExtResource("1_qcjqt") +metadata/_edit_lock_ = true + +[node name="nav" type="NavigationAgent2D" parent="large"] + +[node name="target" type="Node2D" parent="."] +position = Vector2(904, 703)