From 9c583ed694f08c6fb84a567ba6f8e94dc8c7cf43 Mon Sep 17 00:00:00 2001 From: karl Date: Mon, 28 Oct 2019 01:21:41 +0100 Subject: [PATCH] Implement basic path following for Meldewesen The PathNavigatorForKinematicBody node can take a KinematicBody as a child and move it along its path. It doesn't strictly follow the path though, but also avoids obstacles according to the Navigation (with its Navmesh). How the Navigation node is fetched will be changed using Groups later, the current structure is temporary. A PathTestWorld has been added for testing this behavior, as well as a basic Meldewesen. --- Characters/Meldewesen/Meldewesen.gd | 13 ++++ Characters/Meldewesen/Meldewesen.tscn | 60 +++++++++++++++ .../Util/PathNavigatorForKinematicBody.gd | 75 +++++++++++++++++++ .../Util/PathNavigatorForKinematicBody.tscn | 15 ++++ Level/PathTestWorld.tscn | 43 +++++++++++ project.godot | 2 + 6 files changed, 208 insertions(+) create mode 100644 Characters/Meldewesen/Meldewesen.gd create mode 100644 Characters/Meldewesen/Meldewesen.tscn create mode 100644 Characters/Util/PathNavigatorForKinematicBody.gd create mode 100644 Characters/Util/PathNavigatorForKinematicBody.tscn create mode 100644 Level/PathTestWorld.tscn diff --git a/Characters/Meldewesen/Meldewesen.gd b/Characters/Meldewesen/Meldewesen.gd new file mode 100644 index 0000000..355993c --- /dev/null +++ b/Characters/Meldewesen/Meldewesen.gd @@ -0,0 +1,13 @@ +extends KinematicBody + +# Declare member variables here. Examples: +# var a = 2 +# var b = "text" + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + +# Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta): +# pass diff --git a/Characters/Meldewesen/Meldewesen.tscn b/Characters/Meldewesen/Meldewesen.tscn new file mode 100644 index 0000000..d14e109 --- /dev/null +++ b/Characters/Meldewesen/Meldewesen.tscn @@ -0,0 +1,60 @@ +[gd_scene load_steps=8 format=2] + +[ext_resource path="res://Characters/Meldewesen/Meldewesen.gd" type="Script" id=1] + +[sub_resource type="CylinderMesh" id=1] +top_radius = 0.8 + +[sub_resource type="CylinderMesh" id=2] +top_radius = 0.8 +bottom_radius = 0.001 + +[sub_resource type="CylinderShape" id=3] + +[sub_resource type="SpatialMaterial" id=4] +flags_transparent = true +albedo_color = Color( 1, 0, 0, 0.329412 ) + +[sub_resource type="CylinderMesh" id=5] +material = SubResource( 4 ) +top_radius = 4.0 +bottom_radius = 0.001 +height = 6.0 + +[sub_resource type="ConvexPolygonShape" id=6] +points = PoolVector3Array( 0, 3, 4, 0.392069, 3, 3.98074, 0.780361, 3, 3.92314, 1.16114, 3, 3.82776, 1.53073, 3, 3.69552, 1.88559, 3, 3.52769, 2.22228, 3, 3.32588, 2.53757, 3, 3.09204, 2.82843, 3, 2.82843, 3.09204, 3, 2.53757, 3.32588, 3, 2.22228, 3.52769, 3, 1.88559, 3.69552, 3, 1.53073, 3.82776, 3, 1.16114, 3.92314, 3, 0.780361, 3.98074, 3, 0.392069, 4, 3, 2.44929e-16, 3.98074, 3, -0.392069, 3.92314, 3, -0.780361, 3.82776, 3, -1.16114, 3.69552, 3, -1.53073, 3.52769, 3, -1.88559, 3.32588, 3, -2.22228, 3.09204, 3, -2.53757, 2.82843, 3, -2.82843, 2.53757, 3, -3.09204, 2.22228, 3, -3.32588, 1.88559, 3, -3.52769, 1.53073, 3, -3.69552, 1.16114, 3, -3.82776, 0.780361, 3, -3.92314, 0.392069, 3, -3.98074, 4.89859e-16, 3, -4, -0.392069, 3, -3.98074, -0.780361, 3, -3.92314, -1.16114, 3, -3.82776, -1.53073, 3, -3.69552, -1.88559, 3, -3.52769, -2.22228, 3, -3.32588, -2.53757, 3, -3.09204, -2.82843, 3, -2.82843, -3.09204, 3, -2.53757, -3.32588, 3, -2.22228, -3.52769, 3, -1.88559, -3.69552, 3, -1.53073, -3.82776, 3, -1.16114, -3.92314, 3, -0.780361, -3.98074, 3, -0.392069, -4, 3, -7.34788e-16, -3.98074, 3, 0.392069, -3.92314, 3, 0.780361, -3.82776, 3, 1.16114, -3.69552, 3, 1.53073, -3.52769, 3, 1.88559, -3.32588, 3, 2.22228, -3.09204, 3, 2.53757, -2.82843, 3, 2.82843, -2.53757, 3, 3.09204, -2.22228, 3, 3.32588, -1.88559, 3, 3.52769, -1.53073, 3, 3.69552, -1.16114, 3, 3.82776, -0.780361, 3, 3.92314, -0.392069, 3, 3.98074, -9.79717e-16, 3, 4, 0, 1.8, 3.2002, 0.313674, 1.8, 3.18479, 0.624328, 1.8, 3.13871, 0.928969, 1.8, 3.0624, 1.22466, 1.8, 2.9566, 1.50856, 1.8, 2.82232, 1.77794, 1.8, 2.66087, 2.03019, 1.8, 2.47379, 2.26288, 1.8, 2.26288, 2.47379, 1.8, 2.03019, 2.66087, 1.8, 1.77794, 2.82232, 1.8, 1.50856, 2.9566, 1.8, 1.22466, 3.0624, 1.8, 0.928969, 3.13871, 1.8, 0.624328, 3.18479, 1.8, 0.313674, 3.2002, 1.8, 1.95956e-16, 3.18479, 1.8, -0.313674, 3.13871, 1.8, -0.624328, 3.0624, 1.8, -0.928969, 2.9566, 1.8, -1.22466, 2.82232, 1.8, -1.50856, 2.66087, 1.8, -1.77794, 2.47379, 1.8, -2.03019, 2.26288, 1.8, -2.26288, 2.03019, 1.8, -2.47379, 1.77794, 1.8, -2.66087, 1.50856, 1.8, -2.82232, 1.22466, 1.8, -2.9566, 0.928969, 1.8, -3.0624, 0.624328, 1.8, -3.13871, 0.313674, 1.8, -3.18479, 3.91912e-16, 1.8, -3.2002, -0.313674, 1.8, -3.18479, -0.624328, 1.8, -3.13871, -0.928969, 1.8, -3.0624, -1.22466, 1.8, -2.9566, -1.50856, 1.8, -2.82232, -1.77794, 1.8, -2.66087, -2.03019, 1.8, -2.47379, -2.26288, 1.8, -2.26288, -2.47379, 1.8, -2.03019, -2.66087, 1.8, -1.77794, -2.82232, 1.8, -1.50856, -2.9566, 1.8, -1.22466, -3.0624, 1.8, -0.928969, -3.13871, 1.8, -0.624328, -3.18479, 1.8, -0.313674, -3.2002, 1.8, -5.87867e-16, -3.18479, 1.8, 0.313674, -3.13871, 1.8, 0.624328, -3.0624, 1.8, 0.928969, -2.9566, 1.8, 1.22466, -2.82232, 1.8, 1.50856, -2.66087, 1.8, 1.77794, -2.47379, 1.8, 2.03019, -2.26288, 1.8, 2.26288, -2.03019, 1.8, 2.47379, -1.77794, 1.8, 2.66087, -1.50856, 1.8, 2.82232, -1.22466, 1.8, 2.9566, -0.928969, 1.8, 3.0624, -0.624328, 1.8, 3.13871, -0.313674, 1.8, 3.18479, -7.83823e-16, 1.8, 3.2002, 0, 0.6, 2.4004, 0.23528, 0.6, 2.38884, 0.468295, 0.6, 2.35428, 0.696799, 0.6, 2.29704, 0.918593, 0.6, 2.21768, 1.13154, 0.6, 2.11696, 1.33359, 0.6, 1.99586, 1.5228, 0.6, 1.85553, 1.69734, 0.6, 1.69734, 1.85553, 0.6, 1.5228, 1.99586, 0.6, 1.33359, 2.11696, 0.6, 1.13154, 2.21768, 0.6, 0.918593, 2.29704, 0.6, 0.696799, 2.35428, 0.6, 0.468295, 2.38884, 0.6, 0.23528, 2.4004, 0.6, 1.46982e-16, 2.38884, 0.6, -0.23528, 2.35428, 0.6, -0.468295, 2.29704, 0.6, -0.696799, 2.21768, 0.6, -0.918593, 2.11696, 0.6, -1.13154, 1.99586, 0.6, -1.33359, 1.85553, 0.6, -1.5228, 1.69734, 0.6, -1.69734, 1.5228, 0.6, -1.85553, 1.33359, 0.6, -1.99586, 1.13154, 0.6, -2.11696, 0.918593, 0.6, -2.21768, 0.696799, 0.6, -2.29704, 0.468295, 0.6, -2.35428, 0.23528, 0.6, -2.38884, 2.93964e-16, 0.6, -2.4004, -0.23528, 0.6, -2.38884, -0.468295, 0.6, -2.35428, -0.696799, 0.6, -2.29704, -0.918593, 0.6, -2.21768, -1.13154, 0.6, -2.11696, -1.33359, 0.6, -1.99586, -1.5228, 0.6, -1.85553, -1.69734, 0.6, -1.69734, -1.85553, 0.6, -1.5228, -1.99586, 0.6, -1.33359, -2.11696, 0.6, -1.13154, -2.21768, 0.6, -0.918593, -2.29704, 0.6, -0.696799, -2.35428, 0.6, -0.468295, -2.38884, 0.6, -0.23528, -2.4004, 0.6, -4.40946e-16, -2.38884, 0.6, 0.23528, -2.35428, 0.6, 0.468295, -2.29704, 0.6, 0.696799, -2.21768, 0.6, 0.918593, -2.11696, 0.6, 1.13154, -1.99586, 0.6, 1.33359, -1.85553, 0.6, 1.5228, -1.69734, 0.6, 1.69734, -1.5228, 0.6, 1.85553, -1.33359, 0.6, 1.99586, -1.13154, 0.6, 2.11696, -0.918593, 0.6, 2.21768, -0.696799, 0.6, 2.29704, -0.468295, 0.6, 2.35428, -0.23528, 0.6, 2.38884, -5.87928e-16, 0.6, 2.4004, 0, -0.6, 1.6006, 0.156886, -0.6, 1.59289, 0.312262, -0.6, 1.56984, 0.46463, -0.6, 1.53168, 0.612523, -0.6, 1.47876, 0.754517, -0.6, 1.4116, 0.889246, -0.6, 1.33085, 1.01541, -0.6, 1.23728, 1.13179, -0.6, 1.13179, 1.23728, -0.6, 1.01541, 1.33085, -0.6, 0.889246, 1.4116, -0.6, 0.754517, 1.47876, -0.6, 0.612523, 1.53168, -0.6, 0.46463, 1.56984, -0.6, 0.312262, 1.59289, -0.6, 0.156886, 1.6006, -0.6, 9.80085e-17, 1.59289, -0.6, -0.156886, 1.56984, -0.6, -0.312262, 1.53168, -0.6, -0.46463, 1.47876, -0.6, -0.612523, 1.4116, -0.6, -0.754517, 1.33085, -0.6, -0.889246, 1.23728, -0.6, -1.01541, 1.13179, -0.6, -1.13179, 1.01541, -0.6, -1.23728, 0.889246, -0.6, -1.33085, 0.754517, -0.6, -1.4116, 0.612523, -0.6, -1.47876, 0.46463, -0.6, -1.53168, 0.312262, -0.6, -1.56984, 0.156886, -0.6, -1.59289, 1.96017e-16, -0.6, -1.6006, -0.156886, -0.6, -1.59289, -0.312262, -0.6, -1.56984, -0.46463, -0.6, -1.53168, -0.612523, -0.6, -1.47876, -0.754517, -0.6, -1.4116, -0.889246, -0.6, -1.33085, -1.01541, -0.6, -1.23728, -1.13179, -0.6, -1.13179, -1.23728, -0.6, -1.01541, -1.33085, -0.6, -0.889246, -1.4116, -0.6, -0.754517, -1.47876, -0.6, -0.612523, -1.53168, -0.6, -0.46463, -1.56984, -0.6, -0.312262, -1.59289, -0.6, -0.156886, -1.6006, -0.6, -2.94025e-16, -1.59289, -0.6, 0.156886, -1.56984, -0.6, 0.312262, -1.53168, -0.6, 0.46463, -1.47876, -0.6, 0.612523, -1.4116, -0.6, 0.754517, -1.33085, -0.6, 0.889246, -1.23728, -0.6, 1.01541, -1.13179, -0.6, 1.13179, -1.01541, -0.6, 1.23728, -0.889246, -0.6, 1.33085, -0.754517, -0.6, 1.4116, -0.612523, -0.6, 1.47876, -0.46463, -0.6, 1.53168, -0.312262, -0.6, 1.56984, -0.156886, -0.6, 1.59289, -3.92034e-16, -0.6, 1.6006, 0, -1.8, 0.8008, 0.0784921, -1.8, 0.796944, 0.156228, -1.8, 0.785413, 0.23246, -1.8, 0.766318, 0.306453, -1.8, 0.739843, 0.377494, -1.8, 0.706242, 0.444901, -1.8, 0.665841, 0.508022, -1.8, 0.619027, 0.566251, -1.8, 0.566251, 0.619027, -1.8, 0.508022, 0.665841, -1.8, 0.444901, 0.706242, -1.8, 0.377494, 0.739843, -1.8, 0.306453, 0.766318, -1.8, 0.23246, 0.785413, -1.8, 0.156228, 0.796944, -1.8, 0.0784921, 0.8008, -1.8, 4.90348e-17, 0.796944, -1.8, -0.0784921, 0.785413, -1.8, -0.156228, 0.766318, -1.8, -0.23246, 0.739843, -1.8, -0.306453, 0.706242, -1.8, -0.377494, 0.665841, -1.8, -0.444901, 0.619027, -1.8, -0.508022, 0.566251, -1.8, -0.566251, 0.508022, -1.8, -0.619027, 0.444901, -1.8, -0.665841, 0.377494, -1.8, -0.706242, 0.306453, -1.8, -0.739843, 0.23246, -1.8, -0.766318, 0.156228, -1.8, -0.785413, 0.0784921, -1.8, -0.796944, 9.80697e-17, -1.8, -0.8008, -0.0784921, -1.8, -0.796944, -0.156228, -1.8, -0.785413, -0.23246, -1.8, -0.766318, -0.306453, -1.8, -0.739843, -0.377494, -1.8, -0.706242, -0.444901, -1.8, -0.665841, -0.508022, -1.8, -0.619027, -0.566251, -1.8, -0.566251, -0.619027, -1.8, -0.508022, -0.665841, -1.8, -0.444901, -0.706242, -1.8, -0.377494, -0.739843, -1.8, -0.306453, -0.766318, -1.8, -0.23246, -0.785413, -1.8, -0.156228, -0.796944, -1.8, -0.0784921, -0.8008, -1.8, -1.47105e-16, -0.796944, -1.8, 0.0784921, -0.785413, -1.8, 0.156228, -0.766318, -1.8, 0.23246, -0.739843, -1.8, 0.306453, -0.706242, -1.8, 0.377494, -0.665841, -1.8, 0.444901, -0.619027, -1.8, 0.508022, -0.566251, -1.8, 0.566251, -0.508022, -1.8, 0.619027, -0.444901, -1.8, 0.665841, -0.377494, -1.8, 0.706242, -0.306453, -1.8, 0.739843, -0.23246, -1.8, 0.766318, -0.156228, -1.8, 0.785413, -0.0784921, -1.8, 0.796944, -1.96139e-16, -1.8, 0.8008, 0, -3, 0.000999928, 9.801e-05, -3, 0.000995113, 0.000195076, -3, 0.000980714, 0.000290264, -3, 0.000956871, 0.000382656, -3, 0.000923813, 0.000471363, -3, 0.000881857, 0.00055553, -3, 0.000831409, 0.000634347, -3, 0.000772954, 0.000707056, -3, 0.000707056, 0.000772954, -3, 0.000634347, 0.000831409, -3, 0.00055553, 0.000881857, -3, 0.000471363, 0.000923813, -3, 0.000382656, 0.000956871, -3, 0.000290264, 0.000980714, -3, 0.000195076, 0.000995113, -3, 9.801e-05, 0.000999928, -3, 6.12279e-20, 0.000995113, -3, -9.801e-05, 0.000980714, -3, -0.000195076, 0.000956871, -3, -0.000290264, 0.000923813, -3, -0.000382656, 0.000881857, -3, -0.000471363, 0.000831409, -3, -0.00055553, 0.000772954, -3, -0.000634347, 0.000707056, -3, -0.000707056, 0.000634347, -3, -0.000772954, 0.00055553, -3, -0.000831409, 0.000471363, -3, -0.000881857, 0.000382656, -3, -0.000923813, 0.000290264, -3, -0.000956871, 0.000195076, -3, -0.000980714, 9.801e-05, -3, -0.000995113, 1.22456e-19, -3, -0.000999928, -9.801e-05, -3, -0.000995113, -0.000195076, -3, -0.000980714, -0.000290264, -3, -0.000956871, -0.000382656, -3, -0.000923813, -0.000471363, -3, -0.000881857, -0.00055553, -3, -0.000831409, -0.000634347, -3, -0.000772954, -0.000707056, -3, -0.000707056, -0.000772954, -3, -0.000634347, -0.000831409, -3, -0.00055553, -0.000881857, -3, -0.000471363, -0.000923813, -3, -0.000382656, -0.000956871, -3, -0.000290264, -0.000980714, -3, -0.000195076, -0.000995113, -3, -9.801e-05, -0.000999928, -3, -1.83684e-19, -0.000995113, -3, 9.801e-05, -0.000980714, -3, 0.000195076, -0.000956871, -3, 0.000290264, -0.000923813, -3, 0.000382656, -0.000881857, -3, 0.000471363, -0.000831409, -3, 0.00055553, -0.000772954, -3, 0.000634347, -0.000707056, -3, 0.000707056, -0.000634347, -3, 0.000772954, -0.00055553, -3, 0.000831409, -0.000471363, -3, 0.000881857, -0.000382656, -3, 0.000923813, -0.000290264, -3, 0.000956871, -0.000195076, -3, 0.000980714, -9.801e-05, -3, 0.000995113, -2.44912e-19, -3, 0.000999928, 0, 3, 0, 0, 3, 4, 0.392069, 3, 3.98074, 0.780361, 3, 3.92314, 1.16114, 3, 3.82776, 1.53073, 3, 3.69552, 1.88559, 3, 3.52769, 2.22228, 3, 3.32588, 2.53757, 3, 3.09204, 2.82843, 3, 2.82843, 3.09204, 3, 2.53757, 3.32588, 3, 2.22228, 3.52769, 3, 1.88559, 3.69552, 3, 1.53073, 3.82776, 3, 1.16114, 3.92314, 3, 0.780361, 3.98074, 3, 0.392069, 4, 3, 2.44929e-16, 3.98074, 3, -0.392069, 3.92314, 3, -0.780361, 3.82776, 3, -1.16114, 3.69552, 3, -1.53073, 3.52769, 3, -1.88559, 3.32588, 3, -2.22228, 3.09204, 3, -2.53757, 2.82843, 3, -2.82843, 2.53757, 3, -3.09204, 2.22228, 3, -3.32588, 1.88559, 3, -3.52769, 1.53073, 3, -3.69552, 1.16114, 3, -3.82776, 0.780361, 3, -3.92314, 0.392069, 3, -3.98074, 4.89859e-16, 3, -4, -0.392069, 3, -3.98074, -0.780361, 3, -3.92314, -1.16114, 3, -3.82776, -1.53073, 3, -3.69552, -1.88559, 3, -3.52769, -2.22228, 3, -3.32588, -2.53757, 3, -3.09204, -2.82843, 3, -2.82843, -3.09204, 3, -2.53757, -3.32588, 3, -2.22228, -3.52769, 3, -1.88559, -3.69552, 3, -1.53073, -3.82776, 3, -1.16114, -3.92314, 3, -0.780361, -3.98074, 3, -0.392069, -4, 3, -7.34788e-16, -3.98074, 3, 0.392069, -3.92314, 3, 0.780361, -3.82776, 3, 1.16114, -3.69552, 3, 1.53073, -3.52769, 3, 1.88559, -3.32588, 3, 2.22228, -3.09204, 3, 2.53757, -2.82843, 3, 2.82843, -2.53757, 3, 3.09204, -2.22228, 3, 3.32588, -1.88559, 3, 3.52769, -1.53073, 3, 3.69552, -1.16114, 3, 3.82776, -0.780361, 3, 3.92314, -0.392069, 3, 3.98074, -9.79717e-16, 3, 4, 0, -3, 0, 0, -3, 0.001, 9.80171e-05, -3, 0.000995185, 0.00019509, -3, 0.000980785, 0.000290285, -3, 0.00095694, 0.000382683, -3, 0.00092388, 0.000471397, -3, 0.000881921, 0.00055557, -3, 0.00083147, 0.000634393, -3, 0.00077301, 0.000707107, -3, 0.000707107, 0.00077301, -3, 0.000634393, 0.00083147, -3, 0.00055557, 0.000881921, -3, 0.000471397, 0.00092388, -3, 0.000382683, 0.00095694, -3, 0.000290285, 0.000980785, -3, 0.00019509, 0.000995185, -3, 9.80171e-05, 0.001, -3, 6.12323e-20, 0.000995185, -3, -9.80171e-05, 0.000980785, -3, -0.00019509, 0.00095694, -3, -0.000290285, 0.00092388, -3, -0.000382683, 0.000881921, -3, -0.000471397, 0.00083147, -3, -0.00055557, 0.00077301, -3, -0.000634393, 0.000707107, -3, -0.000707107, 0.000634393, -3, -0.00077301, 0.00055557, -3, -0.00083147, 0.000471397, -3, -0.000881921, 0.000382683, -3, -0.00092388, 0.000290285, -3, -0.00095694, 0.00019509, -3, -0.000980785, 9.80171e-05, -3, -0.000995185, 1.22465e-19, -3, -0.001, -9.80171e-05, -3, -0.000995185, -0.00019509, -3, -0.000980785, -0.000290285, -3, -0.00095694, -0.000382683, -3, -0.00092388, -0.000471397, -3, -0.000881921, -0.00055557, -3, -0.00083147, -0.000634393, -3, -0.00077301, -0.000707107, -3, -0.000707107, -0.00077301, -3, -0.000634393, -0.00083147, -3, -0.00055557, -0.000881921, -3, -0.000471397, -0.00092388, -3, -0.000382683, -0.00095694, -3, -0.000290285, -0.000980785, -3, -0.00019509, -0.000995185, -3, -9.80171e-05, -0.001, -3, -1.83697e-19, -0.000995185, -3, 9.80171e-05, -0.000980785, -3, 0.00019509, -0.00095694, -3, 0.000290285, -0.00092388, -3, 0.000382683, -0.000881921, -3, 0.000471397, -0.00083147, -3, 0.00055557, -0.00077301, -3, 0.000634393, -0.000707107, -3, 0.000707107, -0.000634393, -3, 0.00077301, -0.00055557, -3, 0.00083147, -0.000471397, -3, 0.000881921, -0.000382683, -3, 0.00092388, -0.000290285, -3, 0.00095694, -0.00019509, -3, 0.000980785, -9.80171e-05, -3, 0.000995185, -2.44929e-19, -3, 0.001 ) + +[node name="Meldewesen" type="KinematicBody"] +script = ExtResource( 1 ) + +[node name="Meshes" type="Spatial" parent="."] + +[node name="TrueAppearance" type="MeshInstance" parent="Meshes"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0 ) +layers = 2 +mesh = SubResource( 1 ) +material/0 = null + +[node name="MaskedAppearance" type="MeshInstance" parent="Meshes"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0 ) +mesh = SubResource( 2 ) +material/0 = null + +[node name="Collider" type="CollisionShape" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0 ) +shape = SubResource( 3 ) + +[node name="Visibility" type="Area" parent="."] +collision_layer = 4 +collision_mask = 4 + +[node name="VisibilityCone" type="MeshInstance" parent="Visibility"] +transform = Transform( 1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 2, -3 ) +mesh = SubResource( 5 ) +material/0 = null + +[node name="CollisionShape" type="CollisionShape" parent="Visibility"] +transform = Transform( 1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 2, -3 ) +shape = SubResource( 6 ) + +[node name="Navigation" type="Navigation" parent="."] diff --git a/Characters/Util/PathNavigatorForKinematicBody.gd b/Characters/Util/PathNavigatorForKinematicBody.gd new file mode 100644 index 0000000..87cbccf --- /dev/null +++ b/Characters/Util/PathNavigatorForKinematicBody.gd @@ -0,0 +1,75 @@ +extends Path + +var _current_nav_path: PoolVector3Array + +var _current_nav_index = 0 +var _current_path_index = 1 + +var _arrived_distance_threshold = 0.1 + +export(float) var speed = 8 +export(NodePath) var navigation_nodepath +export(NodePath) var body_nodepath + +var navigation: Navigation +var body: KinematicBody + + +func _ready(): + navigation = get_node(navigation_nodepath) as Navigation + body = get_node(body_nodepath) as KinematicBody + + # Initialize the position + body.transform.origin = curve.get_point_position(0) + + # Get the first goal + _get_new_navigation() + + +func _process(delta): + var current_goal = _get_current_goal() + + # Move towards the current goal + var direction = (current_goal - _get_body_position()).normalized() + + body.move_and_slide(direction * speed) + + # Look towards that goal as well + body.look_at(_get_body_position() + direction, Vector3.UP) + + +# Returns the point we should currently be moving towards +func _get_current_goal(): + # If we haven't arrived at the current goal, then that's still the goal + if _current_nav_path[_current_nav_index].distance_to(_get_body_position()) > _arrived_distance_threshold: + return _current_nav_path[_current_nav_index] + + if _current_nav_index < _current_nav_path.size() - 1: + # We still have points left in the current navigation -> use the next one + _current_nav_index += 1 + else: + # We're done following the current navigation to the next path point + if _current_path_index < curve.get_point_count() - 1: + # We still have points left in the path -> use the next one and generate the navigation to it + _current_path_index += 1 + else: + # We're done following the path -> Go back to the start + _current_nav_index = 0 + _current_path_index = 0 + + _get_new_navigation() + + return _current_nav_path[_current_nav_index] + + +# Reset the navigation and build a new one for the current path index +func _get_new_navigation(): + _current_nav_index = 0 + + var goal = curve.get_point_position(_current_path_index) + _current_nav_path = navigation.get_simple_path(_get_body_position(), goal) + + +# Return the current position of the body we're controlling +func _get_body_position(): + return body.transform.origin diff --git a/Characters/Util/PathNavigatorForKinematicBody.tscn b/Characters/Util/PathNavigatorForKinematicBody.tscn new file mode 100644 index 0000000..8f9b2e0 --- /dev/null +++ b/Characters/Util/PathNavigatorForKinematicBody.tscn @@ -0,0 +1,15 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://Characters/Util/PathNavigatorForKinematicBody.gd" type="Script" id=1] + +[sub_resource type="Curve3D" id=4] +_data = { +"points": PoolVector3Array( 0, 0, 0, 0, 0, 0, -7.92509, 2.86102e-05, -6.86376, 0, 0, 0, 0, 0, 0, 0.703341, 0.398803, 1.99739, 0, 0, 0, 0, 0, 0, 9.39952, 0.263628, 7.15156, 0, 0, 0, 0, 0, 0, -4.38803, 1.73835, 6.52798 ), +"tilts": PoolRealArray( 0, 0, 0, 0 ) +} + +[node name="PathNavigatorForKinematicBody" type="Path"] +curve = SubResource( 4 ) +script = ExtResource( 1 ) +navigation_nodepath = NodePath("..") +body_nodepath = NodePath("../KinematicBody") diff --git a/Level/PathTestWorld.tscn b/Level/PathTestWorld.tscn new file mode 100644 index 0000000..7fe2d4d --- /dev/null +++ b/Level/PathTestWorld.tscn @@ -0,0 +1,43 @@ +[gd_scene load_steps=6 format=2] + +[ext_resource path="res://Characters/Util/PathNavigatorForKinematicBody.tscn" type="PackedScene" id=1] +[ext_resource path="res://Characters/Meldewesen/Meldewesen.tscn" type="PackedScene" id=2] + +[sub_resource type="NavigationMesh" id=1] +vertices = PoolVector3Array( -1.3, 0.4, -1.6, 0.200001, 0.4, -1.6, 0.200001, 0.4, -9.4, -9.4, 0.4, -0.0999994, -1.6, 0.4, -0.0999994, -1.3, 0.4, -1.6, 0.200001, 0.4, -9.4, -9.4, 0.4, -9.4, 0.200001, 0.4, -9.4, 0.200001, 0.4, -1.6, 1.4, 0.4, -1.6, 1.4, 0.4, -1.6, 1.7, 0.4, -0.0999994, 9.5, 0.4, -0.0999994, 9.5, 0.4, -9.4, 0.200001, 0.4, -9.4, 0.200001, 0.4, 9.5, 0.200001, 0.4, 8.3, -1.6, 0.4, 8, -9.4, 0.4, 9.5, -1.6, 0.4, 5, 0.200001, 0.4, 4.7, 0.200001, 0.4, 1.7, -1.6, 0.4, 1.4, -1.6, 0.4, 5, -1.6, 0.4, 1.4, -9.4, 0.4, -0.0999994, -9.4, 0.4, 9.5, -1.6, 0.4, 1.4, -1.6, 0.4, -0.0999994, -9.4, 0.4, -0.0999994, -9.4, 0.4, 9.5, -1.6, 0.4, 8, -1.6, 0.4, 5, 1.7, 0.4, 8, 0.200001, 0.4, 8.3, 0.200001, 0.4, 9.5, 9.5, 0.4, 9.5, 0.200001, 0.4, 1.7, 0.200001, 0.4, 4.7, 1.7, 0.4, 5, 1.7, 0.4, 1.4, 1.7, 0.4, 5, 9.5, 0.4, 9.5, 9.5, 0.4, -0.0999994, 1.7, 0.4, 1.4, 1.7, 0.4, 5, 1.7, 0.4, 8, 9.5, 0.4, 9.5, 9.5, 0.4, -0.0999994, 1.7, 0.4, -0.0999994, 1.7, 0.4, 1.4 ) +polygons = [ PoolIntArray( 2, 0, 1 ), PoolIntArray( 7, 3, 6 ), PoolIntArray( 3, 5, 6 ), PoolIntArray( 3, 4, 5 ), PoolIntArray( 10, 8, 9 ), PoolIntArray( 15, 11, 14 ), PoolIntArray( 11, 12, 14 ), PoolIntArray( 12, 13, 14 ), PoolIntArray( 19, 16, 18 ), PoolIntArray( 16, 17, 18 ), PoolIntArray( 23, 20, 22 ), PoolIntArray( 20, 21, 22 ), PoolIntArray( 27, 24, 26 ), PoolIntArray( 24, 25, 26 ), PoolIntArray( 30, 28, 29 ), PoolIntArray( 33, 31, 32 ), PoolIntArray( 37, 34, 36 ), PoolIntArray( 34, 35, 36 ), PoolIntArray( 41, 38, 40 ), PoolIntArray( 38, 39, 40 ), PoolIntArray( 45, 42, 44 ), PoolIntArray( 42, 43, 44 ), PoolIntArray( 48, 46, 47 ), PoolIntArray( 51, 49, 50 ) ] + +[sub_resource type="CubeMesh" id=2] + +[sub_resource type="PlaneMesh" id=3] +size = Vector2( 20, 20 ) + +[node name="Navigation" type="Navigation"] + +[node name="Camera" type="Camera" parent="."] +transform = Transform( 1, 0, 0, 0, 0.866025, 0.5, 0, -0.5, 0.866025, 0, 10, 16 ) +current = true + +[node name="DirectionalLight" type="DirectionalLight" parent="."] +transform = Transform( 0.766044, -0.582564, 0.271654, 0, 0.422618, 0.906308, -0.642788, -0.694272, 0.323744, 0, 5, 0 ) + +[node name="NavigationMeshInstance" type="NavigationMeshInstance" parent="."] +navmesh = SubResource( 1 ) + +[node name="MeshInstance" type="MeshInstance" parent="NavigationMeshInstance"] +mesh = SubResource( 2 ) +material/0 = null + +[node name="MeshInstance3" type="MeshInstance" parent="NavigationMeshInstance"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 6.53892 ) +mesh = SubResource( 2 ) +material/0 = null + +[node name="MeshInstance2" type="MeshInstance" parent="NavigationMeshInstance"] +mesh = SubResource( 3 ) +material/0 = null + +[node name="PathNavigatorForKinematicBody" parent="." instance=ExtResource( 1 )] +body_nodepath = NodePath("Meldewesen") + +[node name="Meldewesen" parent="PathNavigatorForKinematicBody" instance=ExtResource( 2 )] diff --git a/project.godot b/project.godot index afedd05..1556fe6 100644 --- a/project.godot +++ b/project.godot @@ -16,6 +16,7 @@ _global_script_class_icons={ [application] config/name="retrace" +run/main_scene="res://Level/PathTestWorld.tscn" config/icon="res://icon.png" [layer_names] @@ -24,6 +25,7 @@ config/icon="res://icon.png" 3d_physics/layer_1="Masked" 3d_render/layer_2="True" 3d_physics/layer_2="True" +3d_physics/layer_3="Player" [rendering]