NavMeshAgent 组件可帮助您创建在朝目标移动时能够彼此避开的角色。代理 (Agent) 使用导航网格来推断游戏世界,并知道如何避开彼此以及其他移动障碍物。寻路和空间推断是使用导航网格代理的脚本 API 进行处理的。
属性 | 功能 |
---|---|
Agent Size | |
Radius | 代理的半径,用于计算障碍物与其他代理之间的碰撞。 |
Height | 代理通过头顶障碍物时所需的高度间隙。 |
Base offset | 碰撞圆柱体相对于变换轴心点的偏移。 |
Steering | |
Speed | 最大移动速度(以世界单位/秒表示)。 |
Angular Speed | 最大旋转速度(度/秒)。 |
Acceleration | 最大加速度(以世界单位/平方秒表示)。 |
Stopping distance | 当靠近目标位置的距离达到此值时,代理将停止。 |
Auto Braking | 启用此属性后,代理在到达目标时将减速。对于巡逻等行为(这种情况下,代理应在多个点之间平滑移动)应禁用此属性 |
Obstacle Avoidance | |
Quality | 障碍躲避质量。如果拥有大量代理,则可以通过降低障碍躲避质量来节省 CPU 时间。如果将躲避设置为无,则只会解析碰撞,而不会尝试主动躲避其他代理和障碍物。 |
Priority | 执行避障时,此代理将忽略优先级较低的代理。该值应在 0–99 范围内,其中较低的数字表示较高的优先级。 |
Path Finding | |
Auto Traverse OffMesh Link | Set to true to automatically traverse OffMesh links. You should turn this off when you want to use animation or some specific way to traverse OffMesh links. |
Auto Repath | 启用此属性后,代理将在到达部分路径末尾时尝试再次寻路。当没有到达目标的路径时,将生成一条部分路径通向与目标最近的可达位置。 |
Area Mask | Area Mask 描述了代理在寻路时将考虑的区域类型。在准备网格进行导航网格烘焙时,可设置每个网格区域类型。例如,可将楼梯标记为特殊区域类型,并禁止某些角色类型使用楼梯。 |
代理由直立圆柱体定义,而该圆柱体的大小由 Radius 和 Height 属性指定。圆柱体随对象移动,但即使对象本身旋转也始终保持直立。圆柱体的形状用于检测并响应其他代理和障碍物之间的碰撞。当游戏对象的锚点不在圆柱体的底部时,可使用 Base Offset 属性来获取高度差。
圆柱体的高度和半径实际上在_两个_不同的位置指定:导航网格烘焙设置和各代理的属性。
通常在这两个位置设置相同的代理大小。但在某些情况下,例如,一个沉重的士兵可能有更大的半径,所以其他代理会在他周围保持更大间隔空间,但在其他情况下他避开环境的方式是相同的。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.