From 55d1deeeac3bdb89833fd64a0a0787f586ff4187 Mon Sep 17 00:00:00 2001 From: Bojidar Marinov Date: Mon, 8 Apr 2019 16:46:00 +0300 Subject: [PATCH] Fix navigation demo not reaching the final point Fixes #321 --- 2d/navigation/level.tscn | 1 - 2d/navigation/navigation.gd | 17 +++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/2d/navigation/level.tscn b/2d/navigation/level.tscn index f6882a6d..7c4a6f4f 100644 --- a/2d/navigation/level.tscn +++ b/2d/navigation/level.tscn @@ -24,4 +24,3 @@ position = Vector2( 228.464, 132.594 ) scale = Vector2( 0.5, 0.5 ) texture = ExtResource( 3 ) offset = Vector2( 0, -26 ) - diff --git a/2d/navigation/navigation.gd b/2d/navigation/navigation.gd index 11bfcae4..b5a16440 100644 --- a/2d/navigation/navigation.gd +++ b/2d/navigation/navigation.gd @@ -29,17 +29,18 @@ func _process(delta): func move_along_path(distance): var last_point = $Character.position - for _index in range(path.size()): + while path.size(): var distance_between_points = last_point.distance_to(path[0]) + # the position to move to falls between two points - if distance <= distance_between_points and distance >= 0.0: + if distance <= distance_between_points: $Character.position = last_point.linear_interpolate(path[0], distance / distance_between_points) - break - # the character reached the end of the path - elif distance < 0.0: - $Character.position = path[0] - set_process(false) - break + return + + # the position is past the end of the segment distance -= distance_between_points last_point = path[0] path.remove(0) + # the character reached the end of the path + $Character.position = last_point + set_process(false)