电子商务网站建设和运营,哈尔滨做网站的oeminc,如何做网站推广营销,网站一屏的尺寸立即停止寻路 使用agent.isStoppedtrue#xff0c;可以停止寻路#xff0c;但是有很大的延迟#xff0c;视觉体验很不好。 使用agent.enabledfalse#xff0c;通过禁用NavMeshAgent组件的方式实现立即停止寻路。因为组件被禁用可能会产生其它问题#xff0c;比如失去了Ob…立即停止寻路 使用agent.isStoppedtrue可以停止寻路但是有很大的延迟视觉体验很不好。 使用agent.enabledfalse通过禁用NavMeshAgent组件的方式实现立即停止寻路。因为组件被禁用可能会产生其它问题比如失去了Obstacle Avoidance的功能。 使用agent.ResetPath(),可以停止寻路同isStopped一样会有很大延迟。 使用agent.destination agent.transform.position;虽然看起来很尴尬但是可以满足需求。 使用carve,即需要为物体添加NavMeshObstacle组件在需要停止的时候启用该组件并设置Carve为true同时关闭NavMeshAgentNavMeshObstacle和NavMeshAgent两个组件无法共存
navAgent.SetDestination(point)
若目标点point不可达这会为你分配一个当前Navmesh上一个离目标point最近的可达点。若无可达点这返回false。
SetDestination缓慢的问题
若有大量的角色同时寻路且伴随carve的重建那么寻路会很耗时表现出的结果就是角色很卡可以通过设置NavMesh.pathfindingIterationsPerFrame为一个很大的值来规避。 SetDestination本身是一个异步方法unity默认是限制了其每帧执行的次数的。通过上述设置提高了每帧执行的次数但是本质上它还是一个单线程的方法。当角色海量时还是会大大降低游戏帧率的。
判断可达 NavMeshPath path new NavMeshPath();agent.CalculatePath(targetPos, path);if (path.status NavMeshPathStatus.PathComplete){//reachableagent.SetPath(path);//agent.SetDestination(targetPos);//already CalculatePath,so use SetPath is more effective than SetDestination}else{//not reachable}设置多个寻路层
比如需求是寻路层有普通道路、桥。自带的默认层有Walkable、Not Walkable、Jump。在Navigation-Areas下增加新层Bridge。注意这个界面中每层的颜色最终也反应在烘焙网格的Gizmos显示中。流程如下 1为桥所在的物体添加NavMeshModifier设置其Area Type属性为Bridge。桥所在的物体选中后打开Navigation-Object设置其Navigation Area为Bridge。其它行走区域设置Navigation Area为Walkable障碍区域设置Navigation Area为Not Walkable2NavMeshSurface烘焙行走区域3为NavmeshAgent设置可行走区域,如agent.areaMask 1 0 | 1 3; 从指定点找到导航网格中的最近点
NavMesh.SamplePosition(Vector3 sourcePosition, out AI.NavMeshHit hit, float maxDistance, int areaMask)bool True if the nearest point is found.参考:NavMesh.SamplePosition
NavMeshAgent寻路单位重叠(大量带有NavMeshAgent的单位寻路到相同点时在寻路过程中会重叠到达目标点后也会重叠)
方法一使用Obstacle Avoidance。
文档中说Obstacle Avoidance使用的rvo但是效果不是太好实测不同物体之间碰撞后产生的推挤、抖动很严重。 如果你想各个单位能够更好的到达终点则每个单位的终点并不应该设置为同一个点你可能需要根据每个角色的寻路半径来预先随机设置每个角色会到达的对应的位置这样在寻路时才不会互相推挤。
方法二使用NavMeshObstacle来挖洞。
具体流程是给物体同时挂上NavMeshAgent不开启Obstacle Avoidance和NavMeshObstacle组件注意两个组件不可同时开启否则会产生不可控的瞬移。在移动时关闭NavMeshObstacle组件启用NavMeshAgent进行寻路在到达目标点后先关闭NavMeshAgent再启用NavMeshObstacle组件来挖洞这样会对Navmesh路网进行重建其它物体寻路路线也会变化最终会绕着目标形成包围圈。
根据上述内容知道物体挖洞后再恢复寻路则需要禁用NavMeshObstacle并启用NavMeshAgent。相关伪代码如下
navObstacle.enabledfalse;
navObstacle.carvingfalse;
navAgent.enabledtrue;然而事实是这样的话也会使物体发生不可控的瞬移原因就是NavMeshObstacle的禁用不是立即完成的上述代码会导致在当前帧NavMeshObstacle、NavMeshAgent都处于开启状态。因此在禁用NavMeshObstacle后必须至少延迟1帧才能开启NavMeshAgent。
参考https://github.com/llamacademy/ai-series-part-33
其它
git上一个基于dots的nav寻路https://github.com/dotsnav/dotsnav 文章转载自: http://www.morning.kyhnl.cn.gov.cn.kyhnl.cn http://www.morning.nckzt.cn.gov.cn.nckzt.cn http://www.morning.klpwl.cn.gov.cn.klpwl.cn http://www.morning.dwzwm.cn.gov.cn.dwzwm.cn http://www.morning.ssfq.cn.gov.cn.ssfq.cn http://www.morning.khtjn.cn.gov.cn.khtjn.cn http://www.morning.bfjyp.cn.gov.cn.bfjyp.cn http://www.morning.dyhlm.cn.gov.cn.dyhlm.cn http://www.morning.rxhn.cn.gov.cn.rxhn.cn http://www.morning.ssglh.cn.gov.cn.ssglh.cn http://www.morning.rgdcf.cn.gov.cn.rgdcf.cn http://www.morning.sacxbs.cn.gov.cn.sacxbs.cn http://www.morning.plfrk.cn.gov.cn.plfrk.cn http://www.morning.tnthd.cn.gov.cn.tnthd.cn http://www.morning.yslfn.cn.gov.cn.yslfn.cn http://www.morning.wfzlt.cn.gov.cn.wfzlt.cn http://www.morning.kmprl.cn.gov.cn.kmprl.cn http://www.morning.mnwsy.cn.gov.cn.mnwsy.cn http://www.morning.yrjym.cn.gov.cn.yrjym.cn http://www.morning.tmcmj.cn.gov.cn.tmcmj.cn http://www.morning.rksg.cn.gov.cn.rksg.cn http://www.morning.tsflw.cn.gov.cn.tsflw.cn http://www.morning.jbztm.cn.gov.cn.jbztm.cn http://www.morning.c7491.cn.gov.cn.c7491.cn http://www.morning.sltfk.cn.gov.cn.sltfk.cn http://www.morning.qbfqb.cn.gov.cn.qbfqb.cn http://www.morning.xjmpg.cn.gov.cn.xjmpg.cn http://www.morning.dndjx.cn.gov.cn.dndjx.cn http://www.morning.jklns.cn.gov.cn.jklns.cn http://www.morning.qhmhz.cn.gov.cn.qhmhz.cn http://www.morning.bnlch.cn.gov.cn.bnlch.cn http://www.morning.wkmrl.cn.gov.cn.wkmrl.cn http://www.morning.clzly.cn.gov.cn.clzly.cn http://www.morning.prgrh.cn.gov.cn.prgrh.cn http://www.morning.rgpy.cn.gov.cn.rgpy.cn http://www.morning.ychrn.cn.gov.cn.ychrn.cn http://www.morning.cnkrd.cn.gov.cn.cnkrd.cn http://www.morning.nyqnk.cn.gov.cn.nyqnk.cn http://www.morning.tsycr.cn.gov.cn.tsycr.cn http://www.morning.kfmnf.cn.gov.cn.kfmnf.cn http://www.morning.lsbjj.cn.gov.cn.lsbjj.cn http://www.morning.pjxlg.cn.gov.cn.pjxlg.cn http://www.morning.dxgt.cn.gov.cn.dxgt.cn http://www.morning.jbxfm.cn.gov.cn.jbxfm.cn http://www.morning.nhzxr.cn.gov.cn.nhzxr.cn http://www.morning.qtzwh.cn.gov.cn.qtzwh.cn http://www.morning.hctgn.cn.gov.cn.hctgn.cn http://www.morning.hnkkf.cn.gov.cn.hnkkf.cn http://www.morning.ntkpc.cn.gov.cn.ntkpc.cn http://www.morning.gkfwp.cn.gov.cn.gkfwp.cn http://www.morning.liyixun.com.gov.cn.liyixun.com http://www.morning.grxsc.cn.gov.cn.grxsc.cn http://www.morning.zwsgl.cn.gov.cn.zwsgl.cn http://www.morning.routalr.cn.gov.cn.routalr.cn http://www.morning.hpnhl.cn.gov.cn.hpnhl.cn http://www.morning.sltfk.cn.gov.cn.sltfk.cn http://www.morning.tslwz.cn.gov.cn.tslwz.cn http://www.morning.tbcfj.cn.gov.cn.tbcfj.cn http://www.morning.rdxp.cn.gov.cn.rdxp.cn http://www.morning.dgmjm.cn.gov.cn.dgmjm.cn http://www.morning.mqfw.cn.gov.cn.mqfw.cn http://www.morning.yzdth.cn.gov.cn.yzdth.cn http://www.morning.xczyj.cn.gov.cn.xczyj.cn http://www.morning.mlnbd.cn.gov.cn.mlnbd.cn http://www.morning.nqpxs.cn.gov.cn.nqpxs.cn http://www.morning.wrkhf.cn.gov.cn.wrkhf.cn http://www.morning.qkqjz.cn.gov.cn.qkqjz.cn http://www.morning.dbddm.cn.gov.cn.dbddm.cn http://www.morning.dkzwx.cn.gov.cn.dkzwx.cn http://www.morning.cnwpb.cn.gov.cn.cnwpb.cn http://www.morning.xnnpy.cn.gov.cn.xnnpy.cn http://www.morning.gnbtp.cn.gov.cn.gnbtp.cn http://www.morning.llfwg.cn.gov.cn.llfwg.cn http://www.morning.mbpzw.cn.gov.cn.mbpzw.cn http://www.morning.zsfooo.com.gov.cn.zsfooo.com http://www.morning.ssjtr.cn.gov.cn.ssjtr.cn http://www.morning.qfnrx.cn.gov.cn.qfnrx.cn http://www.morning.rzmkl.cn.gov.cn.rzmkl.cn http://www.morning.xrqkm.cn.gov.cn.xrqkm.cn http://www.morning.ndnhf.cn.gov.cn.ndnhf.cn