Initial commit

This commit is contained in:
Daniel Flanagan 2024-02-05 14:40:47 -06:00
commit c2d3c91cf1
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4
7 changed files with 189 additions and 0 deletions

2
.gitattributes vendored Normal file
View file

@ -0,0 +1,2 @@
# Normalize EOL for all files that Git considers text files.
* text=auto eol=lf

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
# Godot 4+ specific ignores
.godot/

1
icon.svg Normal file
View file

@ -0,0 +1 @@
<svg height="128" width="128" xmlns="http://www.w3.org/2000/svg"><rect x="2" y="2" width="124" height="124" rx="14" fill="#363d52" stroke="#212532" stroke-width="4"/><g transform="scale(.101) translate(122 122)"><g fill="#fff"><path d="M105 673v33q407 354 814 0v-33z"/><path fill="#478cbf" d="m105 673 152 14q12 1 15 14l4 67 132 10 8-61q2-11 15-15h162q13 4 15 15l8 61 132-10 4-67q3-13 15-14l152-14V427q30-39 56-81-35-59-83-108-43 20-82 47-40-37-88-64 7-51 8-102-59-28-123-42-26 43-46 89-49-7-98 0-20-46-46-89-64 14-123 42 1 51 8 102-48 27-88 64-39-27-82-47-48 49-83 108 26 42 56 81zm0 33v39c0 276 813 276 813 0v-39l-134 12-5 69q-2 10-14 13l-162 11q-12 0-16-11l-10-65H447l-10 65q-4 11-16 11l-162-11q-12-3-14-13l-5-69z"/><path d="M483 600c3 34 55 34 58 0v-86c-3-34-55-34-58 0z"/><circle cx="725" cy="526" r="90"/><circle cx="299" cy="526" r="90"/></g><g fill="#414042"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></g></svg>

After

Width:  |  Height:  |  Size: 950 B

37
icon.svg.import Normal file
View file

@ -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

16
project.godot Normal file
View file

@ -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"

71
test.gd Normal file
View file

@ -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)

60
test.tscn Normal file
View file

@ -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)