版本:unity 5.4.1 语言:C#
总起:
最近研究的ARPG游戏中,敌人AI的寻路就使用到了NavMesh,Unity该套组件倒也不复杂:三个组件和一个烘培的Map。我这边不讲基础怎么使用,主要是翻译一下各个组件的属性,说说需要注意的事情。主要参考就是官方文档和自己在Unity中的一些实践。
NavMesh中实现了A*算法作为底层的算法,使用NavMesh Agent可以作为角色的目标路径查找代理,而NavMesh Obstacle则是动态的一些障碍物,Off-Mesh Link作为特殊路径点的连接,并且可以与Animator动画组件实现经过特殊路径的动画,比如开门,连接门内门外的路径点,并执行Animator中的开门动画,这样的需求就可以用Off-Mesh Link来实现。
寻路三大组件:
♦ NavMesh Agent:
NavMeshAgent用于角色的寻路代理,可以在预先烘培的NavMesh中找到目标的一条路线,并且尽可能的规避其他的Agent和Obstacle。(直接官方贴图拿来用了)
Radius Radius of the agent, used to calculate collisions between obstacles and other agents.
agent的半径,用于计算该agent和其他agent、obstacle的碰撞。
Height The height clearance the agent needs to pass below an obstacle overhead.
agent的高度,agent可以通过的头顶障碍最小高度。
Base offset Offset of the collision cylinder in relation to the transform pivot point.
agent圆柱碰撞体中心点的偏移值。当Agent创建后,圆柱碰撞体显示过高或过低,用于将其调整到地面。
Speed Maximum movement speed (in world units per second).
agent移动的最大速度(世界空间中以秒单位计算)
Angular Speed Maximum speed of rotation (degrees per second).
agent最大的旋转速度(角度每秒)
Acceleration Maximum acceleration (in world units per second squared).
agent最大的加速度(世界空间单位每秒的平方)
Stopping distance The agent will stop when this close to the goal location.
agent靠近目标时停下的距离
Auto Braking When enabled, the agent will slow down when reaching the destination. You should disable this for behaviors such patrolling, where the agent should move smoothly between multiple points
自动刹车(我总看成baking)