Merge pull request #322 from bojidar-bg/321-navigation-reach-end

Fix navigation demo not reaching the final point
This commit is contained in:
Rémi Verschelde
2019-04-08 16:43:38 +02:00
committed by GitHub
2 changed files with 9 additions and 9 deletions

View File

@@ -24,4 +24,3 @@ position = Vector2( 228.464, 132.594 )
scale = Vector2( 0.5, 0.5 )
texture = ExtResource( 3 )
offset = Vector2( 0, -26 )

View File

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