Fix issues with Meldewesen pathfinding

The NavigationMeshInstance now keeps larger distances from obstacles to
avoid the Meldewesen from colliding with them while traversing the
correct path.

A possible issue with the look_at vector has been fixed as well.
This commit is contained in:
karl 2019-11-11 10:16:03 +01:00
parent d7e76cff6f
commit d2ee524f72
3 changed files with 25 additions and 36 deletions

View File

@ -7,7 +7,7 @@ var _visibility: Area
func _ready():
Logger.set_logger_level(Logger.LOG_LEVEL_DEBUG)
Logger.set_logger_level(Logger.LOG_LEVEL_FINE)
_visibility = get_node(_visibility_path) as Area
if _visibility:

View File

@ -44,12 +44,16 @@ func _process(delta):
var current_goal = _get_current_goal()
# Move towards the current goal
var direction = (current_goal - _get_body_position()).normalized()
var direction: Vector3 = (current_goal - _get_body_position())
var direction_normalized: Vector3 = direction.normalized()
body.move_and_slide(direction * speed)
body.move_and_slide(direction_normalized * speed)
# Look towards that goal as well
body.look_at(_get_body_position() + direction, Vector3.UP)
# Avoid look_at if we're already (almost) there, since that'd be an invalid look direction
# that can be identical to the up vector (which causes problems)
if direction.length() > 0.5:
body.look_at(_get_body_position() + direction_normalized, Vector3.UP)
# Returns the point we should currently be moving towards
@ -60,14 +64,17 @@ func _get_current_goal():
if _current_nav_index < _current_nav_path.size() - 1:
# We still have points left in the current navigation -> use the next one
Logger.trace("Using next point of current navigation")
_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
Logger.trace("Generating navigation to the next path point")
_current_path_index += 1
else:
# We're done following the path -> Go back to the start
Logger.trace("Returning to the start of the path")
_current_nav_index = 0
_current_path_index = 0

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=14 format=2]
[gd_scene load_steps=12 format=2]
[ext_resource path="res://Characters/Player/Player.tscn" type="PackedScene" id=1]
[ext_resource path="res://Characters/Util/PathNavigatorForKinematicBody.tscn" type="PackedScene" id=2]
@ -6,30 +6,27 @@
[ext_resource path="res://Util/NodeGroupNotifier.tscn" type="PackedScene" id=4]
[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 ) ]
vertices = PoolVector3Array( -1.9, 0.4, -2.2, 0.200001, 0.4, -2.5, 0.200001, 0.4, -8.5, -8.5, 0.4, -0.0999994, -2.5, 0.4, -0.0999994, -1.9, 0.4, -2.2, -1.9, 0.4, -2.2, 0.200001, 0.4, -8.5, -8.5, 0.4, -8.5, -8.5, 0.4, -0.0999994, 0.200001, 0.4, -8.5, 0.200001, 0.4, -2.5, 2, 0.4, -2.2, 2, 0.4, -2.2, 2.6, 0.4, -0.0999994, 8.6, 0.4, -0.0999994, 2, 0.4, -2.2, 8.6, 0.4, -0.0999994, 8.6, 0.4, -8.5, 0.200001, 0.4, -8.5, -1.3, 0.4, 3.8, 0.200001, 0.4, 3.8, 0.200001, 0.4, 2.6, -2.2, 0.4, 2, -8.5, 0.4, 8.6, -2.2, 0.4, 8.6, -2.5, 0.4, 5, -2.5, 0.4, 5, -1.3, 0.4, 3.8, -2.2, 0.4, 2, -2.5, 0.4, 5, -2.2, 0.4, 2, -2.5, 0.4, -0.0999994, -8.5, 0.4, -0.0999994, -8.5, 0.4, 8.6, 0.200001, 0.4, 2.6, 0.200001, 0.4, 3.8, 1.4, 0.4, 3.8, 2.3, 0.4, 2, 2.6, 0.4, 5, 2.3, 0.4, 8.6, 8.6, 0.4, 8.6, 2.3, 0.4, 2, 1.4, 0.4, 3.8, 2.6, 0.4, 5, 2.6, 0.4, -0.0999994, 2.3, 0.4, 2, 2.6, 0.4, 5, 8.6, 0.4, 8.6, 8.6, 0.4, -0.0999994 )
polygons = [ PoolIntArray( 2, 0, 1 ), PoolIntArray( 5, 3, 4 ), PoolIntArray( 9, 6, 8 ), PoolIntArray( 6, 7, 8 ), PoolIntArray( 12, 10, 11 ), PoolIntArray( 15, 13, 14 ), PoolIntArray( 19, 16, 18 ), PoolIntArray( 16, 17, 18 ), PoolIntArray( 23, 20, 22 ), PoolIntArray( 20, 21, 22 ), PoolIntArray( 26, 24, 25 ), PoolIntArray( 29, 27, 28 ), PoolIntArray( 34, 30, 33 ), PoolIntArray( 30, 31, 33 ), PoolIntArray( 31, 32, 33 ), PoolIntArray( 38, 35, 37 ), PoolIntArray( 35, 36, 37 ), PoolIntArray( 41, 39, 40 ), PoolIntArray( 44, 42, 43 ), PoolIntArray( 49, 45, 48 ), PoolIntArray( 45, 46, 48 ), PoolIntArray( 46, 47, 48 ) ]
agent/radius = 1.5
[sub_resource type="CubeMesh" id=2]
[sub_resource type="ConcavePolygonShape" id=7]
[sub_resource type="ConcavePolygonShape" id=3]
data = PoolVector3Array( -1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, -1, 1, -1, -1, 1, 1, 1, -1, -1, 1, -1, 1, -1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, 1, 1, 1, 1, -1, 1, -1, 1, 1, 1, -1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1, 1, 1, -1, -1, -1, -1, 1, 1, -1, -1, 1, -1, -1, -1, 1, 1, 1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1, -1, 1, 1, -1, -1, -1, 1, 1, -1, 1, -1, -1, -1, 1, -1, 1, 1, -1, -1, -1, -1, -1 )
[sub_resource type="ConcavePolygonShape" id=8]
[sub_resource type="ConcavePolygonShape" id=4]
data = PoolVector3Array( -1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, -1, 1, -1, -1, 1, 1, 1, -1, -1, 1, -1, 1, -1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, 1, 1, 1, 1, -1, 1, -1, 1, 1, 1, -1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1, 1, 1, -1, -1, -1, -1, 1, 1, -1, -1, 1, -1, -1, -1, 1, 1, 1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1, -1, 1, 1, -1, -1, -1, 1, 1, -1, 1, -1, -1, -1, 1, -1, 1, 1, -1, -1, -1, -1, -1 )
[sub_resource type="PlaneMesh" id=3]
[sub_resource type="PlaneMesh" id=5]
size = Vector2( 20, 20 )
[sub_resource type="ConcavePolygonShape" id=9]
[sub_resource type="ConcavePolygonShape" id=6]
data = PoolVector3Array( 10, 0, 10, -10, 0, 10, 10, 0, -10, -10, 0, 10, -10, 0, -10, 10, 0, -10 )
[sub_resource type="BoxShape" id=4]
[sub_resource type="BoxShape" id=7]
extents = Vector3( 10, 1, 10 )
[sub_resource type="SphereShape" id=5]
[sub_resource type="SphereMesh" id=6]
[node name="Navigation" type="Navigation"]
[node name="Player" parent="." instance=ExtResource( 1 )]
@ -50,7 +47,7 @@ material/0 = null
[node name="StaticBody" type="StaticBody" parent="NavigationMeshInstance/MeshInstance"]
[node name="CollisionShape" type="CollisionShape" parent="NavigationMeshInstance/MeshInstance/StaticBody"]
shape = SubResource( 7 )
shape = SubResource( 3 )
[node name="MeshInstance3" type="MeshInstance" parent="NavigationMeshInstance"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 6.53892 )
@ -60,25 +57,24 @@ material/0 = null
[node name="StaticBody" type="StaticBody" parent="NavigationMeshInstance/MeshInstance3"]
[node name="CollisionShape" type="CollisionShape" parent="NavigationMeshInstance/MeshInstance3/StaticBody"]
shape = SubResource( 8 )
shape = SubResource( 4 )
[node name="MeshInstance2" type="MeshInstance" parent="NavigationMeshInstance"]
mesh = SubResource( 3 )
mesh = SubResource( 5 )
material/0 = null
[node name="StaticBody" type="StaticBody" parent="NavigationMeshInstance/MeshInstance2"]
[node name="CollisionShape" type="CollisionShape" parent="NavigationMeshInstance/MeshInstance2/StaticBody"]
shape = SubResource( 9 )
shape = SubResource( 6 )
[node name="GroundBody" type="StaticBody" parent="NavigationMeshInstance"]
[node name="CollisionShape" type="CollisionShape" parent="NavigationMeshInstance/GroundBody"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0 )
shape = SubResource( 4 )
shape = SubResource( 7 )
[node name="PathNavigatorForKinematicBody" parent="." instance=ExtResource( 2 )]
editor/display_folded = true
body_nodepath = NodePath("Meldewesen")
[node name="Meldewesen" parent="PathNavigatorForKinematicBody" instance=ExtResource( 3 )]
@ -86,17 +82,3 @@ body_nodepath = NodePath("Meldewesen")
[node name="NodeGroupNotifier" parent="." instance=ExtResource( 4 )]
group_name = "Navigator"
node_to_send = NodePath("..")
[node name="DummyPlayer" type="StaticBody" parent="." groups=[
"Player",
]]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 5.65981, 1, 2 )
collision_layer = 5
collision_mask = 5
[node name="CollisionShape" type="CollisionShape" parent="DummyPlayer"]
shape = SubResource( 5 )
[node name="MeshInstance" type="MeshInstance" parent="DummyPlayer"]
mesh = SubResource( 6 )
material/0 = null