浏览代码

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

Fix navigation demo not reaching the final point
Rémi Verschelde 6 年之前
父节点
当前提交
56a2b28c53
共有 2 个文件被更改,包括 9 次插入9 次删除
  1. 0 1
      2d/navigation/level.tscn
  2. 9 8
      2d/navigation/navigation.gd

+ 0 - 1
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 )
-

+ 9 - 8
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)