我可以让内置程序选择方向变化最少AStar
的最短路径吗?
我目前像这样构建我的图表:
extends GridMap
var _astar = AStar.new()
func _ready():
var id = 0
for c in get_used_cells():
var weight = 1.0
if _get_cover(c.x, c.y, c.z):
weight = 9999.0 # impassable tile
_astar.add_point(id, Vector3(c.x, c.y, c.z), weight)
id += 1
for c in get_used_cells():
var center = _astar.get_closest_point(Vector3(c.x, c.y, c.z))
var above = _astar.get_closest_point(Vector3(c.x, c.y, c.z + 1))
var right = _astar.get_closest_point(Vector3(c.x + 1, c.y, c.z))
assert(id > 0)
if above >= 0:
_astar.connect_points(center, above, true)
if right >= 0:
_astar.connect_points(center, right, true)
似乎您只能对点进行加权,而不是边缘,所以我不确定如何选择一个方向而不是另一个方向。它选择的路径似乎总是最大化方向变化: