障碍物
An obstacle is an invisible object which is placed inside a navigation area and is bypassed during pathfinding.障碍物是放置在导航区域内的不可见对象,在寻路过程中会被绕过。
The obstacles can be added to the scene:可以将障碍物添加到场景中:
- As a single node to indicate an area or a node that should be avoided during pathfinding. However, if you change transformation of the node, the obstacle transformation won't change.作为单个节点来指示在寻路过程中应避免的区域或节点。但是,如果更改节点的变换,则障碍物变换不会改变。
- As a child node of a node that should be bypassed. In this case, transformation of the obstacle will change together with the node transformation and a route will always be calculated correctly.作为应绕过的节点的子节点。在这种情况下,障碍物的变换将与节点变换一起更改,并且始终会正确计算路线。
There are 3 types of the obstacles:障碍分为3种类型:
- Obstacle Box is a cuboid-shaped obstacle. Obstacle Box是长方体形的障碍物。
- Obstacle Sphere is a sphere-shaped obstacle. Obstacle Sphere是球形障碍物。
- Obstacle Capsule is a capsule-shaped obstacle. Obstacle Capsule是一个胶囊形的障碍物。
You should choose the most appropriate type depending on the form of the node that should be bypassed during pathfinding.您应根据在寻路过程中应绕过的节点的形式选择最合适的类型。
Usage Example使用范例#
Supposing, you need to add a node that changes its transformation each frame and should be bypassed during pathfinding. In this case, you should do the following:假设您需要添加一个节点,该节点会在每帧中更改其变换,并且在寻路过程中应绕过该节点。在这种情况下,您应该执行以下操作:
-
Place the required node inside the navigation area within which routes will be calculated.将所需的节点放置在将要计算路线的导航区域内。
A cuboid-shaped ObjectMeshDynamic node placed inside the Navigation Sector放置在Navigation Sector内的长方体形状的ObjectMeshDynamic节点 - Add the obstacle of the required type to the scene and combine its position with the node's position.将所需类型的障碍物添加到场景中,并将其位置与节点的位置结合起来。
-
Set the required size for the obstacle.设置障碍物所需的大小。
The obstacle box and the node.障碍箱和节点。 -
In the World Hierarchy window, drag the obstacle node to make it a child of the required node.在World Hierarchy窗口中,将障碍物节点拖动到做个孩子所需节点的数量。
- Now you can create a route from the script. The route will be automatically recalculated when the node transformation changes.现在你可以创建一条路线从脚本。节点转换更改时,将自动重新计算路线。
In the result, the route will be calculated as follows (the route is highlighted with white):结果,将按以下方式计算路线(路线以白色突出显示):
See Also也可以看看#
- The example on Creating a Route within Navigation Area with Obstacles via code.上的例子在有障碍物的导航区域内创建路线通过代码。