【发布时间】:2014-12-01 18:48:15
【问题描述】:
我目前正尝试在我的 2D 横向卷轴程序生成的世界游戏中使用 A* 寻路(想想类似泰拉瑞亚的地形)。
我一直在使用这个资源:http://www.redblobgames.com/pathfinding/a-star/introduction.html
并且一直主要使用下面给出的伪代码:
frontier = PriorityQueue()
frontier.put(start, 0)
came_from = {}
cost_so_far = {}
came_from[start] = None
cost_so_far[start] = 0
while not frontier.empty():
current = frontier.get()
if current == goal:
break
for next in graph.neighbors(current):
new_cost = cost_so_far[current] + graph.cost(current, next)
if next not in cost_so_far or new_cost < cost_so_far[next]:
cost_so_far[next] = new_cost
priority = new_cost + heuristic(goal, next)
frontier.put(next, priority)
came_from[next] = current
我的问题是:在具有大型程序生成世界的 2D 横向滚动条中,我如何选择边界?到特定图块的路径可以是任意距离,显然遍历整个地图似乎是不明智的。
我正在努力有效地做到这一点,所以任何帮助都将不胜感激!
【问题讨论】:
标签: unity3d 2d artificial-intelligence a-star procedural-generation