游戏邦在:
杂志专栏:
gamerboom.com订阅到鲜果订阅到抓虾google reader订阅到有道订阅到QQ邮箱订阅到帮看

分享电子游戏AI寻径方法之最佳寻径选择

发布时间:2014-04-18 11:48:19 Tags:,,,,

作者:Giovanni Guarino

在之前的文章中, 我提到了如果你想创造下一代创新游戏应该考虑采用的新方法,即所谓的生物寻径法(BPF)。我总是认为最普遍使用的模型并非可以不加思索就采用的圣典,怀疑通常是促使我们的大脑创造出更棒AI模式的关键因素。

在阅读本文之前,请确保你已经看过了关于这个话题的前一篇关于导航(Navigation)的文章。(请点击此处阅读本系列第3部分)

创造图表

NavGrid或者NavMesh模型已经够用和够好了,在某些情况下无需任何定制选项。如果你想一次创造一款电子游戏,即那种与他人相似的电子游戏,那么它们就很适合你。如果你的游戏中没有多少NPC,你也不介意他们有时候(或者经常)做出一些人们在行走时根本不会出现的奇怪举动,那么你就没有必要寻找更好的解决方案了。

但是,未来的电子游戏不会使用含有不具有人类行为的NPC。更新的模型应该提供无需定制的新功能,从而实现更好的表现效果。

当前的Navgrid和Navmesh模型具有优势,但劣势则更明显。这两者在某些情况下的离线计算时间都过长了。如果你的游戏中含有多名一起活动的NPC那就不可以使用这两种模型了。

除此之外,针对更宏大并且需要建设高度的3D关卡,我也不建议使用Navgrid。在这种情况下使用Navgrid会增加关联性,导致路径计算更为复杂,从而产生明显的运行问题。

现实中的路径点:焦点

现实中的路径点是否存在相似之物呢?要知道路径点,或者任何形成导航地图的多边形都是NPC在关卡内移动的必需要素。也许你从来没有想过人类和动物在现实中移动都有相似的参照。真正的人类,会根据自己的需求在一条路上采用数量有点的“战略性”位置。

请注意真正的路径。例如,一栋建筑内的路径。你知道没有任何人能够真达自己的目标,除非他身处一个户外区域。他需要更改方向。你是否认为我们能够找到重制真正的人类必须更改方向的位置这一规则呢?

其目标仅考虑人类通常需要更改方向的关键点。这些点可能与走廊相近,介于两个相邻柱子之间,或者靠近一个门柱。

微场景

如果你看一眼某个场景,尤其是人造的场景,你就会看到走廊窄于该场景相邻环节(见图1)。两个墙体形成一个走廊从而创造了一个微场景,门柱是一个狭小的微场景,靠近另一个柱子或墙体的柱子也形成了一个微场景。

我们有不同的Mental Map创造方法来区分微场景。其中一个更简单(也更快)的方法可能就是场景中确定的一系列关键点所产生的线段。第一件事就是检查相关点是否处于一个对象内部 。此时只需要考虑位于外部的相关点。

这里每X个衡量单位都会有一个点。这里的X是与NPC类型范围相兼容的值。我将这一方法称为Radar Node Generation,因为它模拟移动雷达创建其环境表现的方式。

这个解决方案会模拟我们首次踏上一条新路径,记录位置等一系列行为。在现实中,我们的大脑并不会记录下我们所经过的所有位置。另一方面,我所提议方法还会模拟我们大脑计算混乱局面之间的空间这种原始行为(拥有眼睛的所有动物也有这个特点)。

该算法会从每个点发射两条线段:一条在左,一条在右,这两者都指向最远的点。这个方法的执行方式多种多样。例如图2。我们之后就可以查看其中是否存在与更近对象,或者该系列追随点的碰撞。如果之前一个点没有在右侧找到更接的对象,并且找到了当前的一个点,我们就会清楚有个对象更接近这个点。

我们应该能够长度、宽度和高度上制作这个行为。但尽管如此,它还是要取决于关卡复杂度以及开发者。

图1(from gamedev.net)

图1(from gamedev.net)

图2(from gamedev.net)

图2(from gamedev.net)

焦点

什么是焦点?这种点是人类需要改变方向的战略位置。实际上,这个点是人类改变方向的最后一个有用的位置。人类事实上会很自然地更改方向,它始于焦点之前。

焦点对于人类来说有另一个重要性。因为我们的大脑不能像视频一样持续记录一条路径,它只能记录一些重要的地点。Kevin Lynch曾在其著作中提到心理地图(对于某城市的心理地图)的研究:“我们对于一座城市的认知通常不是持续性的,而是局部性,分裂式的,会混杂其他考虑因素。几乎会运用到每种感官,而该图像却是与所有感官相反的。”

他在对于城市心理表征的研究中提到,心理地图应该包含以下类型的数据:

*路径:街道,人行道,轨道以及其他人们会行走的通道。

*边缘,例如墙体、建筑和海岸线等边界物。

*地区,由一些标志或特点所区分出的较大城市部分。

*节点、焦点和交叉点。

*地标,可以作为外部参照点的可辨识性物体。

一个极为可靠的模拟物应该考虑到Lynch所提到的所有数据。当然,这样就会创造出无法在任何游戏中执行的庞大算法。一个好方法就是针对模拟人类和动物采用最重要的标识。

我们应该将焦点布置在微场景中的哪个地方?我们应该将其布置于微场景的每个入口。这些位置是一条真正路径的节点,也将成为我们心理地图的节点。每个微场景必须拥有一两个入口。准确的位置应该是介于创造了微场景的物体之间的中心点。

我们有不同焦点定义的关卡。例如,像图1左半部分,就仅针对每个内部物体的单个维度定义焦点。或者像图1右半部分那样,同时针对宽度和长度定义焦点。而开发了高度的关卡还需要通过查看高度来找到焦点。

前提

根据我在执行BPF方面的一点经验,这里必须定在一些前提条件,即你要很好地执行这个模型所需用到的规则。鉴于文章篇幅所限,我无法在些描述我所搜集到的所有前提条件。以下仅简述我认为比较重要的前提条件:

1.入口

我们在每个微场景中可以有1至2个入口。

2.可视性

微场景的焦点在其局限或者内部中形成并且可以彼此相见。例如,由两个大物体组成的走廊,置至一个更广阔场地的中间,从而创造了两个焦点,每个都位于走廊起点或终点。而在微场景焦点无法彼此相见的地方,我们应该添加一个或更多新焦点。这样每个焦点至少都可以看到另一个焦点。

3.两者合一

如果微场景很小,涉及一个中间NPC(例如介于两根柱子之间)的垂直或纵向维度,而不是创造两个焦点时,算法就只会创造一个焦点。最终两个被删除的焦点中间区域就会产生一个焦点。例如,看看图1中的两个门柱,你就可以看到这种前提的结果。

4.静态物体的半径距离

要考虑关卡中静态物体和表面局限性之间由用户定义的半径距离。这有助于避免产生与静态物体碰撞的焦点之间产生的线段。

5.追随最后一个可视的焦点

焦点只是人类和动物在路径上需要更改方向时所考虑区域的一部分。但是,在路径上行进的过程中,BPF不会让代理走向路径上的下一个焦点,而是其所能“看到”的“最后一个焦点”。这是一个进一步提升代理可信度的创新,也是真正的人类替换成代理时所出现的行为。

图3(from gamedev.net)

图3(from gamedev.net)

看看上图。位于建筑左部的绿色圆圈就是NPC出现的位置,而橙色圆圈则是它的目标。更粗的绿线是NPC所会使用的路径,而较细的紫色线段则是被选择的路径。紫色线段标识着可行的变化,只有能够跳跃的NPC能够看到它们。

正如你所见,NPC会考虑的第二个焦点并非所选择路径上的第二个,而是第三个焦点。NPC会使用的第三个焦点则是其所选择路径上的第五个。这是因为之前所提到的规则。在这个规则中,运行时间会要求NPC不可因为跟随所选择路径上的焦点而浪费时间。NPC会使用所选择路径,而NPC在当前焦点只能看到“最远但仍具可视性”的焦点。

这个例子的结果就在于,NPC将使用的焦点只会有两个而不是五个,这就是心理地图所能提供的焦点。这类解决方案不只是创造更少的路径节点,甚至还会提升人类行为模拟度。

想象一下在身处于NPC相同的情境中真正人类的行为。抛弃所有的路径和节点,想象他在这种情况下是何表现。如果他决定跟随我们的NPC会用到的路径,他当然就会直走,直到碰到建筑中的障碍为止。之后他会开始转向并再次直走,直到建筑又出现障碍,或者到达他的目标为止。

创新游戏的寻径模式应该是怎样的?

回到关于这个话题的普遍讨论,我们可以说创新游戏在不久的将来将拥有更多功能和更好的性能。此外,我们还应该在无需向(并不提供这些功能的)AI模型叠加过多复杂性的前提下实现这些表现性能。

详细来说,创新型的寻径模型应该提供:

*更快速的单个图表离线计算*;

*赋予NPC使用多类路径的能力,例如允许NPC在路径上行走和奔跑,甚至是跳跃、攀爬、游泳等;

*根据每种NPC种类的生理特征,赋予不同NPC选择不同路径的能力;

*更快速的“可信最佳路径”运行时间计算”**;

*在不添加复杂性的前提下解决路径上的动态物体问题;

*找到同种NPC的多个目标(例如,掩体和笨重的物体)***;

*当墙体和大型物体更改其位置时动态调整图表;

*总是考虑到每个NPC的心理地图可能与实际地图并不相同****。

(*)相对于运行时间计算来说,这并非一个强制要求。

(**) 正如心理学所示,我们无法:1)像手上拿着地图那样清楚地记住地图,尤其是在该区域已有一段时间并不“呈现”在NPC面前的时候;2)要避免那种情绪以及快速作出混乱推理的需求,之后确定的路径通常不会是逻辑所提议的选择。

(***) 我想“明智”的游戏会采用自然的NPC人类,以便更好的使用下一代寻径解决方案和创新型决策制定系统的新功能。

(****) 心理学显示人类还可能忘记部分已经用过的路径,或者忘记焦点的准确序列。

可信的路径选择

区域最佳路径选择

BPF与典型的“仅靠逻辑”式的方式截然不同,它不使用当前用于寻找更短路径的算法时会更管用。这里就没有必要追究细节方面的问题了。但是也有一些因素可以让过滤器在无需借助其他算法的情况下选择单个路径。例如,情感权重,心理地图错误,NPC种类的特点,或者关卡的数量,通常有助于挑选出唯一的理想路径。

例如,一个广阔的关卡可能使用10个区域。通常情况下,每个区域都有4个其他与之相连接的区域(除非关卡还要开发高度)。除非该关卡是一系列区域,或者关卡极其庞大,否则一般目标与NPC之间的距离不会超过2个区域。通常情况下,我们没有必要采用任何关于区域关卡的最佳路径算法。

这里有一个可重制人类行为,用于限制路径数量的简单而有效的解决方案。其目标是避开所有首个区域距离NPC及其目标之间的直线过远的路径(假设NPC知道地图)。之后你还要移除至少包括一个用于“避免”NPC类型的区域的路径。

例如,在以下情况中,决策制定系统或者在设计过程中的开发者应该将该区域标注为“避开”类型:

*如果该区域充斥大量可能杀死NPV的危险怪物。

*如果该区域充满不可行,或者不适用于该NPC类型的微场景。

*如果该路径包括更黑暗的区域,以及NPC的个人特点将其视为没有胆量进入的区域。

另一个过滤器就是每个路径的“长度感”。这个过滤器应该难以执行,但却真的很管用。它是我们大脑中最常用的过滤器之一。人类和最高智能的动物会考虑一条路径的长度感。生物体的长度感是由多个因素决定的。其中之一就是过去的旅程所发生的情绪(那种感觉越好,其想象的长度就越短)。

另一个就是路径多为直线或曲折的这一现实。如果你想使用这个符合某些心理研究的过滤器,你甚至可以为任何焦点创造一两个标注。你还可以创造其他过滤器,但我它是相对于路径类型来说最重要的一者。这个标注的职责就是存储始于该焦点的微场景的类型。

从本文的图片中可以看到,一个焦点可能仅靠近一个微场景(图1),或者介于两个微场景中间(图4)。未被选中的标注意味着该迷你场景是直线的,而有被选中的标注则意味着它是曲折的。该路径上被选中的标注数量越多,NPC使用该路径的可能性就越小。

图4(from gamedev.net)

图4(from gamedev.net)

(图4:焦点及其两个标注指示两个相邻微场景的类型)

更进一步的过滤器就是NPC对于这些区域的认知。这是另一个精心设计的人类模拟方法所要考虑的重要功能。BPF可以随机创造区域地图的情况,制作每个NPC或物种。如果是长寿的NPC,你就应该记录每个NPC所行走过的地点。

通常情况下会产生1至2条路径,最多只有3条。如果有多条路径时应该使用哪个路径呢?最应该选择的是包含NPC走向目标时穿过最多次区域的路径。但这个解决方案会被每条路径所包括的区域数量所抵消。

过滤器应考虑以下方面:

*只能选择首个区域离NPC及其目标之间的直线不会过远的区域路径。

*只能选择不含“避开”区域的路径。

*考虑路径的长度感。

*只能选择含有已知区域的路径。

如果这一筛选结果产生了一条以上的区域路径:

*那就选择拥有区域数量较少/或者NPC及其目标之间的直线被穿行过更多次的区域的路径。

内部可信的路径选择

在确定要跟随哪条区域路径后,NPC就得开始解决在当前区域内部的寻径问题。之后,在进入下一个区域时,再重复一遍这种做法。将关卡划分为多个区域(方块)通常会产生多个可行(或者更管用)的表面连接两个区域的情况。这意味着NPC在特定区域路径上进入下一个区域可能有多个解决方法。

将路径划分为两个关卡可以加快可信路径选择的运行时间,并迫使你将寻径划分为多个步骤。尽管如此,要正确使用这一方法,你还是需要应对一些新问题。

如果两个区域之间有走廊,那就有两个关于路径设计时间阐述方面的问题:“死亡路径”以及区域走廊的连接性。事实上,如果某个连接了两个相邻区域的可行路径深入了无法穿过下一站的区域,那么NPC之前就该知道这个问题了。

为了修复这个问题,我们在设计时间应该为每个区域选择从一个相邻区域进入另一个区域的路径。这可能会是一项很耗时间的计算,尤其是相邻区域之间的走廊数量极多的时候。此时可以人为更改区域,以免两个区域之间存在太多联系。

无论如何,其算法应该遵从以下原则:

A-选择区域

A1-选择某一边至少有一个通向相邻区域的区域。

A11-针对每个走廊检查它是否存在可通向另一个相邻区域的路径。如果有,将该走廊标注为可同另一区域兼容的走廊。

这里没有必要计算每条路径的长度了。

BPF的运行时间环节将使用与通向下个区域相关的可行走廊的数据,以便检查该选择哪条走廊走向下个区域。

如果这里存在1条以上通下向个区域的走廊,就要由NPC来决定要走哪条路。你可以使用区域关卡寻径所采用的同种过滤器来选择。我建议考虑长度感以及相对于走向目标的直线走廊距离来选择。

要开始内部路径运行时间选择,你必须知道内部路径以及通向下个区域的走廊的早期环节。前者是NPC进入区域的所在地,或者NPC所在位置。当你两者兼具时,你应该选择该路径走向下条路径寻找目标。即使如此,你也要使用之前所提到的过滤器。但你可以决定要使用哪一种还是全部使用。

注意,如果你的项目是策略型战争游戏那就不可以用这种NPC思维方式。策略型战争游戏是每个NPC已经清楚路径的少数游戏类型。在这种情况下,比较好的解决方法仍然是仅靠逻辑的方法。你应该添加的唯一过滤器就是目前NPC的情感觉醒水平(游戏邦注:相当于音乐的音量)。但这并非直接由PF系统所管理的问题。

尽管如此,你还是很容易注意到生物寻径方法远比目前使用的寻径方法速度更快。我之所以如此确定是因为BPF的执行方式更轻便。

总结

生物寻径方法是一种不但对人类、僵尸、怪物和外星模拟物,甚至是智能动物都很有创新性的解决方法。

尽管如此,我们还是不可低估寻径问题之下的情感因素。即使是决策的能力,也不是一种仅靠逻辑就可制定的功能。Plutchik称情感是一切有机体在追求个体生存时所需要的基本适应性。他认为6亿年前的寒武纪中发生的自然选择很大程度上与情感有关。这8种适应性是结合、拒绝、毁灭、保护、繁殖、机体重组、定向和探索。

这意味着,多种动物都具有心理导航的最重要过滤器。

所以,人类解决寻径问题的方式与动物有何不同?其区别相当之小,主要与逻辑的使用相关。这也并不完全正确。但其中深刻原因我无法在此详述,也难以用代码重现。

多数动物无法通过训练更好地驾驭自己的情感,也无法考虑1个以上的过滤器选择。如果你想区分人与动物在寻径选择方面的行为(或者不同智能的动物行为),只要使用针对最简单动物的一个过滤器即可。之后,当你遇到人类(或者更高智能动物)时再运用其他过滤器。

你应该时时使用的唯一过滤器就是关于首个焦点指向目标方向的路径选择。

关于本文最后一个考虑就是:两个(或多个)层次的寻径方法要求你采用允许NPC具有更多目标层次的决策制定系统。这是你选择BPF时需要牢记在心的另一个重要问题。

下篇文章将关注心理地图、避开动态物体和平顺移动的话题。(本文为游戏邦/gamerboom.com编译,拒绝任何不保留版权的转载,如需转载请联系:游戏邦

Path Finding for innovative games: Graph Creation and Best Path Selection

By Giovanni Guarino

path finding ai artificial intelligence navigation meshes navigation grid waypoint navigationm mental navigation intelligent agent dynamic object avoidance biological path finding psychology

In the previous article, I mentioned a new approach you should consider if you want to build next-gen, innovative games, called Biological Path Finding (BPF). I always thought that the most used models are not a bible, to use without thinking about, and that doubts are often the factor that brings our mind to create better AI models.

Please note that you need to read the previous article of this topic (relative to the Navigation), before reading this one.

Graph Creation

NavGrid or the NavMesh models are enough and good, without any customization, in several circumstances. If you want to build a single video game a time, for a video game similar to others, they can be perfect for you. If you have few NPCs living together, and you don’t mind that they sometimes (or often) do what humans never do when walking, there is no reason why you should find for something better.

Conversely, the future of video games will not use NPCs with a less-than-good human behaviour. Newer models should provide new features without the need to customize, to have better performance.

The current Navgrid and Navmesh models have good pros, but even stronger cons. Both could make, in several circumstances, long time for the off-line calculations. You should not use them when there are several NPCs living together in a wider level. If you want your game go fast, or if the correctness of the human behaviour is a must, you shall find something new and different.

Besides, it’s not recommended the use of Navgrid for wider 3D levels, whom also develop in height. The use of the Navgrid in that context raises connections a lot, letting the path calculation be even more complex, with obvious performance issues.

Waypoints in the reality: the focal points

Can waypoints have a counterpart in the reality? You know that waypoints, or any kind of polygons that form a navigation map, are fundamental for NPCs to move across levels. Probably you never thought that also humans and animals need to have similar references when they move in the reality. A real human, with his needs, have to have a limited number of “strategic” positions along a path.

Please put your attention to a real path. For instance, a path inside a building. You know that no living being can go straight to its target, unless it is in an open space. It has the need to change direction. Do you think we can find a rule with which reproduce the positions in which a real living being should necessarily change its direction?

The goal is considering only points where a human need usually to change his direction. These points can be next to a corridor, between two neighboring columns, a doorpost and so on.

Micro-environments

If you take a look at an environment, especially a human-made one, you can see there are some parts where the passage is narrower respect to the contiguous parts of the environment (see the figure 1). Two walls forming a corridor make a micro-environment; a doorpost is a thin micro-environment; a column close to a wall or to another column forms a micro-environment.

There can be different ways to build the Mental Map and, then, identify micro-enviroments. One of the easier (and the faster, in case you have one or more wider zones in the level) is possible thanks to the launch of linecasts from a series of points defined in the environment. The first thing to do is checking whether the reference point is inside an object or not. Only the reference point outside objects will be considered.

There will be a point each X units of measure. The X is a value compatible with the width of the species of NPCs. I named this approach Radar Node Generation, because it emulates the way with which a moving radar builds up its representation of the environment.

This solution simulates the behaviour of our mind when, the first time we walk a new path, records positions, clutters and so on. In the reality, our mind don’t record all the positions in which we have been (as stated by Lynch). On the other hand, the approach I have proposed emulates, also, the ancient behaviour of our mind (shared with all living beings whom owns eyes) whom calculates the spaces between clutters.

The algorithm will launch two linecasts from each single point: one to its left and one to its right, both toward the farthest point. The implementation of this approach can vary. Anyway, see the figure 2 for an example. We then need to check whether there is a collision with a closer object respect to the previous or the following point along the series. If, for example, the previous point hasn’t found any closer object on the right of it, and the current point has found one, we could clearly state there is (from this point on) an object closer to the point.

We should/could made this action in length, width and height. Nevertheless it depends on the level complexity, and is up to the developer. There are several tips that makes the action performance-compliant, but it’s not the place in which to talk about it.

Figure 1

Figure 2

Focal Points

What are Focal Points? These kinds of points are the strategic position in which living beings need to change direction. In reality, that point is the last useful position for them to change their direction. Living beings, in fact, change direction smoothly, starting a bit before the focal point.

Focal point have another great importance for living beings. As our mind can’t record in memory a path with something similar to a video, something continuous, it records only the important places. I prefer to mention what Kevin Lynch said in his prominent contribution and study of mental maps (referred to the mental map of a city): “Most often our perception (of the city) is not sustained, but rather partial, fragmentary, mixed with other concerns. Nearly every sense is in operation, and the image is the composite of them all.” (Lynch, 1960, p 2.).

Always referring to his studies of the city mental representation, he said that mental maps should contain the following types of data:

paths: the streets, sidewalks, trails, and other channels in which people travel;

edges, perceived boundaries such as walls, buildings, and shorelines;

districts, relatively large sections of the city distinguished by some identity or character;
nodes, focal points, intersections;

landmarks, readily identifiable objects which serve as external reference points.

A strictly reliable simulation should consider all the data mentioned by Lynch. Anyway, this would build a huge algorithm that no one will implemented in any game. A good approach, then, is taking all the most important notice for a human and animal simulation.

Where we need to put the Focal Points respect to the micro-environment? We should position them one for each entrance of the micro-environment. Those positions are the nodes of a real path, and will be the nodes of our Mental Map. Each micro-environment must have one or two entrances. The exact position will be the central point between the objects creating the micro-environment.

We can have different levels of Focal Point identification. For instance, one that identifies focal points only for a single dimension for each inner object, like in the Figure 1 in the left part. Or, like in the Figure 1 in the right part, one that identifies FP for both the width and length dimension. A level that develops even in height should also find FP by checking with the height dimension.

Postulates

My (little) experience in implementing the BPF leads me to say there must be some postulations, some rules that you should use to make a great implementation of this model. I can’t describe all the postulations I’ve collected, because of the reduced space of an article. The ones I don’t describe, anyway, are not too much. Their importance, also, is less than the ones of the postulations I’m going to describe.

1- Entrances

We can have one or two entrances for a micro-environment.

2- Visibility

A micro-environment is such if the focal points created at its limit or inside it see one each other. For example, a corridor formed by two big objects, placed in the middle of a wider place, leads the design-time elaboration create two focal points, each at the beginning (or ending) of the corridor. Where the focal points of the micro-environment can’t see one each other (in case of a rounded corridor, for instance), we should add one or more new focal points along the micro-environment. In this way, each focal point can see at least one other focal point.

3- Two become One

If the micro-environment is small, speaking about one dimension (horizontal or vertical) referred to the size of a medium NPC (for instance, between two columns), instead of creating two focal points, the algorithm will create only one. This resultant focal point will take place in the middle of the space between the deleted focal points. For instance, look at the two doorposts in the Figure 1, where you can see the result of this postulation.

4- Radius Distance toward static objects

Consider a user-defined radius distance between the static object of the level and the limit of the surface. This could help in avoiding to have lines between focal points that collides with static objects.

5- Follow the last visible Focal Point

Focal points are the only parts of any zone that humans and animals consider, in a path, when they need to change direction. However, during the movement along the path, the BPF (Biological Path Finding) states the agent will go not toward the next focal point, but toward the “last focal point”, along the path, the agent can “see”. This is an innovation that improve further the agent’s credibility, and this is what really humans do when are in place of agents.

Figure 3

Look at the previous image. The Green Circle, located in the left part of the building, is the position where the NPC takes place, while the Orange Circle is its target. The wider green line is the path the NPC will use thanks to the BPF, while the thin violet line is the selected path. The Violet Circles, instead, sign the change of viability, and only the NPCs able to jump (at a defined height) will see them.

As you can see, the second focal point the NPC will take into consideration is not the second in the selected path, but the third. The third the NPC will use is the fifth of the selected path. This is because of the previously mentioned rule. With it, the run-time approach states the NPC will not lose time by following each focal point of the chosen path. Contrarily, the NPC will use, of the chosen path, only the “farthest, still visible” focal points the NPC can see from the current focal point.

The result for the example is that the number of focal points the NPC will use is only two, instead of five, as provided by the path of the mental map. A solution like that will not only produce, most likely, the lesser number of path nodes ever, but even will improve the human behaviour simulation.

Consider a real person in the same context of the NPC of the linked image (the building is a church). Throw away all the paths and focal points, and imagine how he behaves in that context. If he decides to follow the path that our NPC will use, he certainly goes straightforward, until the encumbrances of the buildings will allow him. Then, he will start to turn (a bit in advance respect to the focal point) to go another time straight until the building will allow him, or until he reaches his target.

Please note that here there has been an almost completed discussion about the Mental Map of the BPF. Nonetheless, in the last article I prefer to talk again about that part, because its better implementation should consider some other factors.

How a Path Finding model for innovative games should be?

Coming back to the general discussion of this topic, we can say the generation games and, especially, the innovative games, in the early future will have the need to have more features and better performance. Also, we will have the need to reach those performance without putting complexity over complexity on an AI model that does not already provide those features.

In detail, an innovative path finding model should provide:

A faster off-line calculation of the single graph, respect to the current ones*.

Ability to use multi-genre paths for NPCs, by letting NPCs use not only walk and run along the path, but even jump, climb, swim etc.

Ability to have different good paths for different species of NPC, according with the physical characteristics of each NPC species

A faster run-time calculation of the “believable best path”**

Resolve the problem of the dynamic objects along the paths with no added complexity

Find multiple targets even of the same species (for example, shelters and bulky objects)***

Change the graph dynamically when walls and big objects change their positions

Take always into consideration that the mental map of each NPC can be different from the actual map****

(*) This is not a mandatory need, respect to the one of the run-time calculations.

(**) As the Psychology states (Lynch, 1960, )(Tversky, 1993) we can’t: 1) Remember a map as if he owns the map physically on his hands, especially if the zone is not “lived” by the NPC for a while. 2) Avoid that emotions and the need to decide fast confuse reasoning, and then the decided path can often be not the one the logic would propose.

(***) It’s time, I reckon, that ‘smart’ games will adopt the natural subdivision among NPCs, in order to better use the new features of the next-gen path finding solutions and innovative decision-making systems.

(****) Psychology states that humans can also forgot parts of an already-used path, or make mistakes in remembering the exact sequence of the focal points (Moar, Bower, 1983)(Sadalla, Montello, 1989)(Hirtle, Mascolo, 1992)(Byrne, 1979)(Lloyd, Heivly, 1987)(McNamara, 1986)

Believable Path Selection

District Best Path Selection

BPF is so different respect to the classic, “only-logic” approach, that work better without any use of the current algorithms used to find the shorter path. It’s worth not going into details, for this issue. However, there are several factors for which the filters can bring to select a single path with no help of other algorithms. For example, the weight of emotions, mental map errors, the traits of NPC species or the limited number of levels, will usually bring to have only one path that overcomes all the filters.

For example, a wide level could use 10 districts (see my previous article for more details). Normally, each district could have four other districts connected to them (unless the level develops even in height). Unless the level is a sequence of districts, or the level is huge, it’s rare that the target is distant more than two districts from the NPC. Usually, then, it’s useless to adopt any calculation of the best path, about the District level (see the previous article).

There is a simple and effective solutions to limit the number of paths that reproduces the human behaviour. Its goal is avoiding all the paths whose first district is not far from the straight line between the NPC and its target (presuming the NPC knows the map, at least broadly). After that, you should also remove the paths containing at least one district checked as “to avoid” for the species type of NPC.

For instance, the decision-making system or even the developer in design-time should flag the district as “to avoid” (or even the developer in design-time):

If a district is full of dangerous monsters that can kill the NPC.

If a district is full of micro-environments non-viable, or is viable with difficulty for that NPC species.

If the path contains a darker zone, and the personal traits of the NPC (if available) depicts it as a non-courageous individual.

Another filter is the “sensation of length” of each path. Look at this filter, because it should be difficult to implement but really useful. It is one of the most used filters by our mind. Humans and the most intelligent animals should consider the sensation of length of a path (Sadalla, Staplin 1980)(Maki, 1981). There can be several factors that could take place in defining the length sensed by a biological entity. One of them is the emotions proven during the past traversals (the better the sensations proven, the smaller the perceived lenght).

Another one is the fact that the path is mostly straight or tortuous. If you want to use this filter that matches with some psychological studies (Sadalla, Staplin, 1980), you can even create one or two flags for any focal point. There are even other filters you can create, but let me say this is on of the most important among the ones relative to the typology of the path. The duty of this flag is store the type of the micro-enviroments that starts after the focal point.

As you can see in the figures of this article, a focal point can stay close to only one micro-environment (see the Figure 1), or in the middle of two micro-environments (see the Figure 4). The flag unchecked could mean that the mini-environment is straight, while the flag checked means that it is tortuous. The higher the number of checked flags along the path, the lower the likelihood that any NPC will use that path.

Figure 4

An example of a focal point and its two flags suggesting the type of the two adjoining micro-environment.

A further filter is about the NPC knowledge of the districts. This is another important feature that a well-done human simulation could consider. The BPF could create randomly the knowledge map of the district, made per NPC or per Species. In case of long-living NPCs, you should do it by recording the places travelled for each NPC.

Normally, the result should be one or two paths, maximum three of them. What is then the one to use, if there are more than one of them? The path to use will be the one containing the highest number of districts traversed by the linecast that goes from the NPC toward the target. This solution, though, should be counterbalanced by the number of districts of each path.

To recap the filters:

Only the district paths whose first district is not far from the direct line between the NPC and its target

Only paths without “to avoid” districts

Sensation of the Length of the Path

Only paths with known districts

If the result is more than one district path:

Take the path with the lower number of districts or/and consider the higher number of district traversed by the direct line between the NPC and its target

Inner Believable Path Selection

After having decided the district path to follow, the NPC has to start to resolve the path finding inside the current district. Then, when inside the next districts, redo the same for that district. Dividing the level into districts (cubes) normally leads to have several cases into which more than one walkable (or better usable) surface links two districts. This means that an NPC could have more than one solution to go to the next district of the chosen district path.

Dividing the paths into two levels speeds up the run-time selection of the believable path, and forces you to split the path finding into more than one step. Nonetheless, to use the approach correctly, there are some new issues with which you should face with.

In case of the passage between two districts, there are two things the design-time elaboration of the paths should check: the “dead paths” and the connections between passages through districts. In fact, if one of the possible paths whom connect two adjoining districts stops into the district without the possibility to pass to another one, the NPC should know previously about this issue.

To fulfil the problem, in design-time we shall select, for each district, the paths that travel the district by going from one adjoining district to another district. This could be a time-consuming calculation, especially if the number of the passages between adjoining districts is high. This could be a good reason to change manually the districts, to avoid having too many links between two districts.

Anyway, the algorithm should be the following:

A – select the district

A1 – select one side of the district where there is at least one passage to the adjoining district

A11 – For each passage, check if there is a path that conduct to another adjoining district. If so, flag the passage as compatible with the passage to that district (in the way you wish).

There is no need to calculate the length of each path, and this helps a bit.

The run-time part of the BPF will use the data relative to the possible passages to the next districts, to check which passage to select for going to the next district.

If there are more than one passages that traverse the district toward the next one, the NPC mind should decide which to use. How? You should use the same filters adopted to the district level of the path finding. Anyway, I suggest to use one or two, between the sensed length and the distance of the passage respect to the direct line toward the target.

To start the run-time selection of the inner path, you need to know the early part of the inner path and the passage to the next district. The former is where the NPC is entering the district, or where the NPC is placed. When you have both, you shall select the path to use for arriving to your next path finding goal. Even in this case, you should use the filters already discussed. It’s up to you to decide which of them, or use all.

Note, though, that this way of thinking of the NPC is not the right way if your project is a tactical war game. The tactical war game is one of the rare cases in which the paths could be already well known by each NPC “at the table”. In this case, then, a good solution remains one of the correct, only-logic approaches. The only filter you should add is the level of arousal of the emotions currently lived by the NPC (arousal is, for emotions, something similar to the volume for the music). This is, though, an issue not direct managed by the PF system.

Nonetheless, you could easily note the Biological approach should be faster than the current ones. The reasons I affirm that is because the actions executed by BPF are lightweight. In fact, in any case there is a reduced number of nodes in the graph, even thanks to the paths leveling (see the first article for more info).

Conclusion

The biological approach to a path finding, inherent the Biological Path Finding, is an innovative solution not only for humans, zombies, monsters and aliens simulation, but even for intelligent animals.

Nevertheless, never underestimate the role of emotions under the path finding issue. Even the ability to decide, like the one explained in this article, is a feature made not only by logic. As a confirmation of this statement, Plutchik said that emotions are basic adaptations needed by all organisms in the struggle for individual survival (1980, p. 145). He suggested that the selection occurred in the Cambrian era, 600 million years ago, was responsible for most of our emotions. The eight adaptations are incorporation, rejection, destruction, protection, reproduction, reintegration, orientation and exploration.

This means, also, that a wide variety of animals can share the most important filters of the Mental Navigation.

So, what differs from humans way to solve a path finding to the ones of animals? The difference is rather small, and is specifically related to the use of logic. This is not entirely true, by the way. Nonetheless, the causes of this are so deep and so difficult to reproduce in code that I prefer not to mention.

Most animals cannot use training to better govern their emotions, and they are also unable to consider more than one deduction about the filters adopted. If you want to distinguish the human behaviour to the animal one (or among animals with different intelligence) toward the decision for the path selection, use only one filter for the simplest animals. Then, apply other filters when you are facing with humans (or more intelligence animals).

The only filter you should always use is the one about the selection of the paths whose first focal point is toward the direction of the target.

A last consideration I wish to put into the article is the following: as you could state, the two (or more) level Path Finding requires you to have a Decision-Making system whom allows NPCs have more levels of goals. This is another important issue to bear in mind when you chose the BPF.

The next article will focus on the Mental Map, Dynamic Object Avoidance and Smoothing movements.(source:gamedev


上一篇:

下一篇: