Skip to content

Commit 56a2b28

Browse files
authored
Merge pull request #322 from bojidar-bg/321-navigation-reach-end
Fix navigation demo not reaching the final point
2 parents 17e8007 + 55d1dee commit 56a2b28

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

2d/navigation/level.tscn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,3 @@ position = Vector2( 228.464, 132.594 )
2424
scale = Vector2( 0.5, 0.5 )
2525
texture = ExtResource( 3 )
2626
offset = Vector2( 0, -26 )
27-

2d/navigation/navigation.gd

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,18 @@ func _process(delta):
2929

3030
func move_along_path(distance):
3131
var last_point = $Character.position
32-
for _index in range(path.size()):
32+
while path.size():
3333
var distance_between_points = last_point.distance_to(path[0])
34+
3435
# the position to move to falls between two points
35-
if distance <= distance_between_points and distance >= 0.0:
36+
if distance <= distance_between_points:
3637
$Character.position = last_point.linear_interpolate(path[0], distance / distance_between_points)
37-
break
38-
# the character reached the end of the path
39-
elif distance < 0.0:
40-
$Character.position = path[0]
41-
set_process(false)
42-
break
38+
return
39+
40+
# the position is past the end of the segment
4341
distance -= distance_between_points
4442
last_point = path[0]
4543
path.remove(0)
44+
# the character reached the end of the path
45+
$Character.position = last_point
46+
set_process(false)

0 commit comments

Comments
 (0)