博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
A* Pathfinding Project4.2.0
阅读量:6883 次
发布时间:2019-06-27

本文共 3903 字,大约阅读时间需要 13 分钟。

Multiple agent types

This page explains how to handle different agent types, such as agents of different sizes.

When you have agents of different sizes they usually cannot take the same routes to the target. Fortunately it is easy to solve this problem. The easiest way is to create multiple graphs, one for each type of agent. If you have a lot of different agent types, or perhaps even a continous spectrum, you may want to group them as having a large number of graphs will increase memory usage and scanning will take longer. On the  it is possible to set which graphs that the Seeker can use.

 

See

For grid graphs there are also two additional methods that can be used, they are explained in the  section.

Example

Lets say we have these two agents:

 

In the  inspector we can then create 2 different graphs, with the only difference being the character radius that is used (any other parameters can of course be changed if necessary). In this example a recast graph has been used, but this can just as easily be done with another graph type.

 

 

 

 

 

 

When scanning these graphs we will get a result that looks something like this. With the graph for the smaller agent in blue and the graph for the larger agent in purple.

 

On the Seeker component we can then set which graph each agent should use:

 

Now both agents will use graphs appropriate for their size:

Other approaches for grid graphs

As an alternative method on grid graphs it is possible to make the graph generate different  depending on the distance to the nearest obstacle. This only requires a single graph.

See

There is also another approach that is very flexible, but unfortunately has a higher computational cost. For a path request one can supply an  object (see also this tutorial: ) which allows your code to determine exactly which nodes should not be traversable. Using this we can add custom code to instead of just checking if the current node is traversable, we can check all nodes around it as well in for example a 3x3 or 5x5 square (with the default being equivalent to a 1x1 square).

In the below image you can see it used with a 3x3 square. Note that it does not want to traverse the nodes right next to obstacles even though they are walkable, because it checks in a 3x3 square around it.

 

The major advantage of the ITraversalProvider approach is that it will handle all things that can make a node not be traversable. For example you might use different tags to restrict agent movement, however even if you use multiple graphs the different agents will still be able to walk right up to a region that is not traversable becasue of its tag even if the agent has a very large size. With this approach it will not be able to move as close to it because the nodes with another tag will be detected as not traversable and the NxN nodes around the agent must all be traversable.

The ITraversalProvider can be implemented like this:class GridShapeTraversalProvider : ITraversalProvider {

Int2[] shape;
public static GridShapeTraversalProvider SquareShape (int width) {
if ((width % 2) != 1) throw new .ArgumentException("only odd widths are supported");
var shape = new GridShapeTraversalProvider();
shape.shape = new Int2[width*width];
// Create an array containing all integer points within a width*width square
int i = 0;
for (int x = -width/2; x <= width/2; x++) {
for (int z = -width/2; z <= width/2; z++) {
shape.shape[i] = new Int2(x, z);
i++;
}
}
return shape;
}
public bool CanTraverse (Path path, GraphNode node) {
GridNodeBase gridNode = node as GridNodeBase;
// Don't do anything special for non-grid nodes
if (gridNode == null) return DefaultITraversalProvider.CanTraverse(path, node);
int x0 = gridNode.XCoordinateInGrid;
int z0 = gridNode.ZCoordinateInGrid;
var grid = gridNode.Graph as GridGraph;
// Iterate through all the nodes in the shape around the current node
// and check if those nodes are also traversable.
for (int i

转载地址:http://itnbl.baihongyu.com/

你可能感兴趣的文章
vue 2.0 - props
查看>>
RustCon Asia 实录 | Rust 在国内某视频网站的应用
查看>>
Vue遇上Analytics
查看>>
mysql
查看>>
修改max_allowed_packet(允许执行的sql最大长度)
查看>>
node js 处理时间分析
查看>>
判断数据库、表和字段是否存在
查看>>
新手安装postgreSQL后无法连接服务器
查看>>
递归和动态规划
查看>>
java实现简单的控制台管理系统
查看>>
建造模式
查看>>
深入理解 intent (1)
查看>>
将导航栏始终固定在窗口顶部:
查看>>
手机免流量,还会是天方夜谭吗?
查看>>
find命令
查看>>
Java 多线程(四)——线程同步(synchronized、ReentrantLock)
查看>>
遇到Could not load file or assembly ... or one of its dependencies怎么办
查看>>
TCP 上传文件
查看>>
Java练习-001
查看>>
Scribe安装及配置方法
查看>>