Unity3D Note - 场景寻路篇

1.设置场景对象或者说是地面为导航静态(navigation static)

Unity3D Note - 场景寻路篇Unity3D Note - 场景寻路篇Unity3D Note - 场景寻路篇

2.打开window菜单选中Navigation,打开标签页,选中bake分页执行烘焙操作,生成寻路导航路径数据(场景准备完毕)

3.给移动物体添加NavMeshAgent组件,调用SetDestination方法,传个目标点,就可以让其跑跑跑。【如果移动不了,可以查看下 isStopped 和 enable这两个参数有没有设置对】

网上找的API和面板属性 翻译如下:

    Base offset                与地面偏移高度
    speed                        移动速度
    Angular Speed             转角速度 ,转身速度    角速度: 最高转速(度/秒)。
    Acceleration                 加速度,启动时的 最大加速度。
    Stopping Distance         停止距离 ,,制动距离:制动距离。到目的地的距离小于这个值,代理减速。
    Auto Traverse OffMesh Link 自动遍历OffMesh链接:自动移动并关闭OffMeshLinks
    Auto Repath                 自动重新寻路:如果现有的部分已失效,获得新的路径。
    Height                         高度:代理的高度(用于调试图形)。
    Base offset                   基本偏移:碰撞几何体相对于实际几何体垂直的偏移。
    Obstacle Avoidance Type 障碍躲避类型 :躲避的质量水平。
    NavMesh Walkable          导航网格行走:指定代理可以遍历的导航网格层类型。这个参数很有用,在接下来的实例中可以用到。

----------------------------华丽的分割线------------------------------------------------------------------------

所有NavMeshAgent 函数和变量翻译
NavMeshAgent.acceleration 加速度
NavMeshAgent.ActivateCurrentOffMeshLink **当前分离网格链接
NavMeshAgent.angularSpeed 角速度
NavMeshAgent.areaMask 区域遮挡
NavMeshAgent.autoBraking 自动制动
NavMeshAgent.autoRepath 自动重新获取路径
NavMeshAgent.autoTraverseOffMeshLink 自动穿过OffMeshLink
NavMeshAgent.avoidancePriority 逃避优先级
NavMeshAgent.baseOffset 基础偏移
NavMeshAgent.CalculatePath 计算路径
NavMeshAgent.CompleteOffMeshLink 完成分离网格链接
NavMeshAgent.currentOffMeshLinkData 当前关闭网格连接数据
NavMeshAgent.desiredVelocity 需求速度
NavMeshAgent.destination 目的地
NavMeshAgent.FindClosestEdge 寻找最近边缘
NavMeshAgent.GetAreaCost 获取区域成本
NavMeshAgent.hasPath 有路径
NavMeshAgent.height 高度
NavMeshAgent.isOnNavMesh 是否在导航网格上
NavMeshAgent.isOnOffMeshLink 是否在OffMeshLink上
NavMeshAgent.isPathStale 是否是旧路径
NavMeshAgent.Move 移动
NavMeshAgent.nextOffMeshLinkData 下一个OffMeshLink数据
NavMeshAgent.nextPosition 下个位置
NavMeshAgent.obstacleAvoidanceType 障碍逃避类型
NavMeshAgent.path 路径
NavMeshAgent.pathPending 路径等待
NavMeshAgent.pathStatus 路径状况
NavMeshAgent.radius 半径
NavMeshAgent.Raycast 射线投影
NavMeshAgent.remainingDistance 剩余距离
NavMeshAgent.ResetPath 重新设置路径
NavMeshAgent.Resume 恢复
NavMeshAgent.SamplePathPosition 样本路径位置
NavMeshAgent.SetAreaCost 设置区域成本
NavMeshAgent.SetDestination 设置目的地
NavMeshAgent.SetPath 设置路径
NavMeshAgent.speed 速度
NavMeshAgent.steeringTarget 转向目标
NavMeshAgent.Stop 刹车
NavMeshAgent.stoppingDistance 刹车距离
NavMeshAgent.updatePosition 更新位置
NavMeshAgent.updateRotation 更新旋转
NavMeshAgent.velocity 速度
NavMeshAgent.Warp 弯曲

----------------------------华丽的分割线------------------------------------------------------------------------

核心代码:

接收屏幕点击坐标创建射线,检测碰撞点,计算寻路点,将目标移动到该坐标(确保移动距离够大,agent运行中)

Unity3D Note - 场景寻路篇Unity3D Note - 场景寻路篇Unity3D Note - 场景寻路篇

Unity3D Note - 场景寻路篇Unity3D Note - 场景寻路篇Unity3D Note - 场景寻路篇

--------------------------- Private game note  -----------------------------------------------------------------------