diff --git a/Character.tscn b/Character.tscn index 3190937..ade5d8a 100644 --- a/Character.tscn +++ b/Character.tscn @@ -10,9 +10,17 @@ script = ExtResource("1_32tgv") [node name="CollisionShape3D" type="CollisionShape3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) shape = SubResource("CapsuleShape3D_4w3u7") -[node name="NavigationAgent3D" type="NavigationAgent3D" parent="."] - -[node name="MeshInstance3D" type="MeshInstance3D" parent="."] +[node name="MeshInstance3D" type="MeshInstance3D" parent="CollisionShape3D"] mesh = SubResource("CapsuleMesh_2wqp7") +skeleton = NodePath("../..") + +[node name="NavigationAgent3D" type="NavigationAgent3D" parent="."] +debug_enabled = true + +[node name="Timer" type="Timer" parent="."] +wait_time = 2.0 +one_shot = true +autostart = true diff --git a/character.gd b/character.gd index 95925b2..0666219 100644 --- a/character.gd +++ b/character.gd @@ -8,18 +8,19 @@ var movement_target_position: Vector3 = Vector3(-3.0,0.0,3.5) func _ready(): # These values need to be adjusted for the actor's speed # and the navigation layout. - navigation_agent.path_desired_distance = 0.5 - navigation_agent.target_desired_distance = 0.75 - - # Make sure to not await during _ready. + navigation_agent.path_desired_distance = 0.2 + navigation_agent.target_desired_distance = 0.5 + actor_setup.call_deferred() func actor_setup(): # Wait for the first physics frame so the NavigationServer can sync. await get_tree().physics_frame + + var node = get_tree().get_nodes_in_group('FishingSpot')[0] # Now that the navigation map is no longer empty, set the movement target. - set_movement_target(movement_target_position) + set_movement_target(node.global_position) func set_movement_target(movement_target: Vector3): navigation_agent.set_target_position(movement_target) diff --git a/dock.tscn b/dock.tscn new file mode 100644 index 0000000..04e87ec --- /dev/null +++ b/dock.tscn @@ -0,0 +1,44 @@ +[gd_scene load_steps=5 format=3 uid="uid://n1o3m7g342dk"] + +[ext_resource type="Script" path="res://dock_link.gd" id="1_a7ngo"] + +[sub_resource type="CylinderMesh" id="CylinderMesh_oms63"] + +[sub_resource type="NavigationMesh" id="NavigationMesh_uiteq"] +vertices = PackedVector3Array(-1.22348, 0.620972, -8.72268, -1.22348, -0.379028, 2.87732, 1.17652, -0.379028, 2.87732, 1.17652, 0.620972, -8.72268, -1.22348, 0.620972, 0.557321, 1.17652, 0.620972, 0.557321) +polygons = [PackedInt32Array(1, 4, 2), PackedInt32Array(2, 4, 5), PackedInt32Array(5, 4, 0), PackedInt32Array(5, 0, 3)] +cell_size = 0.1 +cell_height = 0.1 +agent_radius = 1.0 + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_jdlc2"] +albedo_color = Color(0.27, 0.17235, 0.1026, 1) + +[node name="Dock" type="Node3D"] + +[node name="FishingSpot" type="Node3D" parent="." groups=["FishingSpot"]] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.00458121, 0.773074, -6.92475) + +[node name="MeshInstance3D" type="MeshInstance3D" parent="FishingSpot"] +transform = Transform3D(0.207282, 0, 0, 0, 1, 0, 0, 0, 0.207282, 0, 0, 0) +mesh = SubResource("CylinderMesh_oms63") + +[node name="NavigationRegion3D" type="NavigationRegion3D" parent="."] +navigation_mesh = SubResource("NavigationMesh_uiteq") + +[node name="Dock" type="CSGCombiner3D" parent="NavigationRegion3D"] + +[node name="CSGBox3D" type="CSGBox3D" parent="NavigationRegion3D/Dock"] +transform = Transform3D(4.44697, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -4.61133) +size = Vector3(1, 1, 10.2227) +material = SubResource("StandardMaterial3D_jdlc2") + +[node name="CSGBox3D2" type="CSGBox3D" parent="NavigationRegion3D/Dock"] +transform = Transform3D(4.44697, 0, 0, 0, 0.906919, -0.421305, 0, 0.421305, 0.906919, 0, -0.737325, 1.98096) +size = Vector3(1, 1, 3.74191) +material = SubResource("StandardMaterial3D_jdlc2") + +[node name="DockLink" type="NavigationLink3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 2.37046) +end_position = Vector3(0, 0, 2) +script = ExtResource("1_a7ngo") diff --git a/dock_link.gd b/dock_link.gd new file mode 100644 index 0000000..abdc488 --- /dev/null +++ b/dock_link.gd @@ -0,0 +1,21 @@ +extends NavigationLink3D + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + _flatten_link.call_deferred() + + +func _flatten_link() -> void: + await get_tree().physics_frame + + var map: RID = get_world_3d().get_navigation_map() + + var start = to_global(start_position) + var end = to_global(end_position) + + print('Moving end from', end) + + start_position = to_local(NavigationServer3D.map_get_closest_point(map, start)) + end_position = to_local(NavigationServer3D.map_get_closest_point(map, end)) + print('to', end_position) diff --git a/lake.tscn b/lake.tscn index 7bd73bb..a1762ec 100644 --- a/lake.tscn +++ b/lake.tscn @@ -1,18 +1,28 @@ -[gd_scene load_steps=3 format=3 uid="uid://b5i2qmhgqp617"] +[gd_scene load_steps=5 format=3 uid="uid://b5i2qmhgqp617"] + +[ext_resource type="PackedScene" uid="uid://n1o3m7g342dk" path="res://dock.tscn" id="1_1av3j"] +[ext_resource type="PackedScene" uid="uid://cu1bnkqxd1nyh" path="res://Character.tscn" id="1_ptn04"] [sub_resource type="NavigationMesh" id="NavigationMesh_nu02n"] -vertices = PackedVector3Array(-49.5, 2, -39.8369, -19.75, 2, -39.5869, -19.5, 2, -41.8369, -18.75, 2, -42.5869, -10.5, 2, -47.8369, -10.5, 2, -94.8369, -49.5, 2, -94.8369, -8.5, 2, -47.5869, -8.25, 2, -94.8369, -3.25, 2, -46.5869, -3, 2, -94.8369, 2, 2, -45.5869, 2.25, 2, -94.8369, 7.25, 2, -44.5869, 7.5, 2, -94.8369, 25.25, 2, -29.3369, 25.25, 2, -27.8369, 49.5, 2, -28.0869, 10.5, 2, -44.0869, 49.5, 2, -94.8369, -20.5, 2, -28.3369, -49.5, 2, -28.3369, -21.5, 2, -15.5869, -49.5, 2, -15.5869, 26.25, 2, -21.0869, 49.5, 2, -21.3369, 27.25, 2, -13.3369, 49.5, 2, -13.5869, -21.5, 2, -14.0869, -13.5, 2, -1.08691, -12.25, 2, -0.0869141, -49.5, 2, 49.4131, -4, 2, 49.4131, -3.75, 2, 2.66309, -6, 2, 2.41309, 27.75, 2, -9.83691, 27.5, 2, -7.83691, 49.5, 2, -7.83691, 23, 2, 1.41309, 20.5, 2, 2.66309, 19.25, 2, 49.4131, 49.5, 2, 49.4131, 19, 2, 2.66309) -polygons = [PackedInt32Array(2, 1, 0), PackedInt32Array(3, 2, 0), PackedInt32Array(3, 0, 4), PackedInt32Array(4, 0, 5), PackedInt32Array(5, 0, 6), PackedInt32Array(5, 8, 4), PackedInt32Array(4, 8, 7), PackedInt32Array(8, 10, 7), PackedInt32Array(7, 10, 9), PackedInt32Array(10, 12, 9), PackedInt32Array(9, 12, 11), PackedInt32Array(12, 14, 11), PackedInt32Array(11, 14, 13), PackedInt32Array(17, 16, 15), PackedInt32Array(15, 18, 17), PackedInt32Array(17, 18, 14), PackedInt32Array(17, 14, 19), PackedInt32Array(13, 14, 18), PackedInt32Array(21, 0, 20), PackedInt32Array(20, 0, 1), PackedInt32Array(23, 21, 22), PackedInt32Array(22, 21, 20), PackedInt32Array(25, 24, 17), PackedInt32Array(17, 24, 16), PackedInt32Array(27, 26, 25), PackedInt32Array(25, 26, 24), PackedInt32Array(23, 22, 28), PackedInt32Array(23, 28, 29), PackedInt32Array(29, 30, 23), PackedInt32Array(23, 30, 31), PackedInt32Array(31, 30, 32), PackedInt32Array(32, 34, 33), PackedInt32Array(32, 30, 34), PackedInt32Array(37, 36, 35), PackedInt32Array(26, 27, 35), PackedInt32Array(35, 27, 37), PackedInt32Array(38, 36, 37), PackedInt32Array(38, 37, 39), PackedInt32Array(39, 37, 40), PackedInt32Array(40, 37, 41), PackedInt32Array(40, 42, 39), PackedInt32Array(33, 42, 32), PackedInt32Array(32, 42, 40)] +vertices = PackedVector3Array(-19.6, 1.7, -42.537, -19, 1.7, -42.737, -10.9, 1.7, -48.237, -49, 1.7, -41.337, -20.1, 1.7, -41.237, -20.1, 1.7, -41.837, -9.9, 1.7, -48.437, -9.9, 1.7, -94.337, -49, 1.7, -94.337, -7.8, 1.7, -48.037, -7.7, 1.7, -94.337, -5.7, 1.7, -47.637, -5.6, 1.7, -94.337, -3.6, 1.7, -47.237, -3.5, 1.7, -94.337, -1.5, 1.7, -46.837, -1.4, 1.7, -94.337, 0.600002, 1.7, -46.437, 0.700001, 1.7, -94.337, 2.7, 1.7, -46.037, 2.8, 1.7, -94.337, 4.8, 1.7, -45.637, 4.9, 1.7, -94.337, 6.9, 1.7, -45.237, 7, 1.7, -94.337, 9, 1.7, -44.837, 9.1, 1.7, -94.337, 25.6, 1.7, -29.637, 25.8, 1.7, -29.137, 49, 1.7, -29.137, 10.7, 1.7, -44.437, 49, 1.7, -94.337, -20.4, 1.7, -37.237, -49, 1.7, -37.237, -20.8, 1.7, -31.937, -49, 1.7, -31.937, -21.2, 1.7, -26.737, -49, 1.7, -26.737, 25.7, 1.7, -28.837, 26.1, 1.7, -26.337, 49, 1.7, -26.437, -21.6, 1.7, -21.537, -49, 1.7, -21.537, 26.5, 1.7, -23.237, 49, 1.7, -23.337, 26.9, 1.7, -20.137, 49, 1.7, -20.237, -22, 1.7, -16.337, -49, 1.7, -16.337, 27.3, 1.7, -17.037, 49, 1.7, -17.137, 27.7, 1.7, -13.937, 49, 1.7, -14.037, -22.1, 1.7, -15.137, -49, 1.7, -15.037, -13.5, 1.7, -0.336998, -21.3, 1.7, -13.237, -21.7, 1.7, -13.637, -22, 1.7, -14.237, -3.9, 1.7, 48.963, -5.5, 1.7, 3.063, -12.8, 1.7, 0.163002, -49, 1.7, 48.963, -3.9, 1.7, 3.36301, -4.7, 1.7, 3.36301, 28.1, 1.7, -10.837, 49, 1.7, -10.937, 28.3, 1.7, -9.437, 28.2, 1.7, -8.237, 49, 1.7, -8.237, 27.5, 1.7, -7.237, 23.4, 1.7, 1.563, 20.9, 1.7, 2.96301, 19.8, 1.7, 3.36301, 19, 1.7, 48.963, 22.9, 1.7, 2.063, 49, 1.7, 48.963, 19, 1.7, 3.36301) +polygons = [PackedInt32Array(1, 0, 2), PackedInt32Array(2, 0, 3), PackedInt32Array(5, 4, 3), PackedInt32Array(0, 5, 3), PackedInt32Array(2, 3, 6), PackedInt32Array(6, 3, 7), PackedInt32Array(7, 3, 8), PackedInt32Array(7, 10, 6), PackedInt32Array(6, 10, 9), PackedInt32Array(10, 12, 9), PackedInt32Array(9, 12, 11), PackedInt32Array(12, 14, 11), PackedInt32Array(11, 14, 13), PackedInt32Array(14, 16, 13), PackedInt32Array(13, 16, 15), PackedInt32Array(16, 18, 15), PackedInt32Array(15, 18, 17), PackedInt32Array(18, 20, 17), PackedInt32Array(17, 20, 19), PackedInt32Array(20, 22, 19), PackedInt32Array(19, 22, 21), PackedInt32Array(22, 24, 21), PackedInt32Array(21, 24, 23), PackedInt32Array(24, 26, 23), PackedInt32Array(23, 26, 25), PackedInt32Array(29, 28, 27), PackedInt32Array(27, 30, 29), PackedInt32Array(29, 30, 26), PackedInt32Array(29, 26, 31), PackedInt32Array(30, 25, 26), PackedInt32Array(33, 3, 32), PackedInt32Array(32, 3, 4), PackedInt32Array(35, 33, 34), PackedInt32Array(34, 33, 32), PackedInt32Array(37, 35, 36), PackedInt32Array(36, 35, 34), PackedInt32Array(38, 28, 39), PackedInt32Array(39, 28, 40), PackedInt32Array(40, 28, 29), PackedInt32Array(42, 37, 41), PackedInt32Array(41, 37, 36), PackedInt32Array(44, 43, 40), PackedInt32Array(40, 43, 39), PackedInt32Array(46, 45, 44), PackedInt32Array(44, 45, 43), PackedInt32Array(48, 42, 47), PackedInt32Array(47, 42, 41), PackedInt32Array(50, 49, 46), PackedInt32Array(46, 49, 45), PackedInt32Array(52, 51, 50), PackedInt32Array(50, 51, 49), PackedInt32Array(54, 48, 53), PackedInt32Array(53, 48, 47), PackedInt32Array(56, 55, 57), PackedInt32Array(57, 55, 54), PackedInt32Array(54, 53, 58), PackedInt32Array(54, 58, 57), PackedInt32Array(61, 60, 59), PackedInt32Array(55, 61, 54), PackedInt32Array(54, 61, 62), PackedInt32Array(62, 61, 59), PackedInt32Array(64, 63, 59), PackedInt32Array(60, 64, 59), PackedInt32Array(66, 65, 52), PackedInt32Array(52, 65, 51), PackedInt32Array(69, 68, 67), PackedInt32Array(65, 66, 67), PackedInt32Array(67, 66, 69), PackedInt32Array(70, 68, 71), PackedInt32Array(71, 68, 69), PackedInt32Array(72, 74, 73), PackedInt32Array(75, 71, 69), PackedInt32Array(75, 69, 72), PackedInt32Array(72, 69, 74), PackedInt32Array(74, 69, 76), PackedInt32Array(74, 77, 73), PackedInt32Array(63, 77, 59), PackedInt32Array(59, 77, 74)] +cell_size = 0.1 +cell_height = 0.1 +agent_radius = 1.0 [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_mmd0r"] albedo_color = Color(0.0853566, 0.29, 0.0783, 1) [node name="Lake" type="Node3D"] +[node name="Dock" parent="." instance=ExtResource("1_1av3j")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.58845, 2.04383, 0.11732) + [node name="NavigationRegion3D" type="NavigationRegion3D" parent="."] navigation_mesh = SubResource("NavigationMesh_nu02n") [node name="Level" type="CSGCombiner3D" parent="NavigationRegion3D"] +use_collision = true [node name="CSGBox3D" type="CSGBox3D" parent="NavigationRegion3D/Level"] transform = Transform3D(100, 0, 0, 0, 3, 0, 0, 0, 100, 0, 0, -22.6685) @@ -21,6 +31,8 @@ material = SubResource("StandardMaterial3D_mmd0r") [node name="LakeArea" type="CSGCombiner3D" parent="NavigationRegion3D/Level"] operation = 2 +metadata/_edit_group_ = true +metadata/_edit_lock_ = true [node name="CSGBox3D" type="CSGBox3D" parent="NavigationRegion3D/Level/LakeArea"] transform = Transform3D(8.96721, 0, 0, 0, 5.63, 0, 0, 0, 4.82575, 7.63805, 0, -4.49351) @@ -61,3 +73,12 @@ size = Vector3(1.23151, 1, 5.03125) [node name="CSGBox3D10" type="CSGBox3D" parent="NavigationRegion3D/Level/LakeArea"] transform = Transform3D(8.28348, 0, 1.84821, 0, 5.63, 0, -3.43435, 0, 4.4578, 20.2467, 9.53674e-07, -0.416638) size = Vector3(0.334114, 1, 1) + +[node name="Character" parent="." instance=ExtResource("1_ptn04")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -19.8339, 1.86631, 8.91661) + +[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] +transform = Transform3D(1, 0, 0, 0, -0.877682, 0.479243, 0, -0.479243, -0.877682, 0, 6.82306, 0) + +[node name="Camera3D" type="Camera3D" parent="."] +transform = Transform3D(-4.37114e-08, -0.707107, 0.707107, 0, 0.707107, 0.707107, -1, 3.09086e-08, -3.09086e-08, 10.1826, 10.1796, 0) diff --git a/project.godot b/project.godot index aa298ed..8d39b0b 100644 --- a/project.godot +++ b/project.godot @@ -19,6 +19,11 @@ config/icon="res://icon.svg" version_control/plugin_name="GitPlugin" version_control/autoload_on_startup=true +[navigation] + +3d/default_cell_size=0.1 +3d/default_cell_height=0.1 + [rendering] renderer/rendering_method="gl_compatibility"