美文网首页
Unity-NaviMesh

Unity-NaviMesh

作者: 祝你万事顺利 | 来源:发表于2019-05-17 09:28 被阅读0次

    1.对我们的可寻路场景物体进行Navagition的烘焙(Bake),可寻路的物体我们将它设置为静态(static),我们在Areas中设置要bake的物体为什么区域,修改权重(Cost)。
    2.给物体添加NavMeshAgent
    3.添加脚本,引入UnityEngine.AI命名空间

        private NavMeshAgent navMeshAgent;
    
        public float speed;
        public Transform Target;
    
        private void Awake()
        {
            navMeshAgent = GetComponent<NavMeshAgent>();
            navMeshAgent.speed = speed;
        }
    
        private void Start()
        {
            navMeshAgent.SetDestination(Target.position);
    
        }
    

    OffMeshLink:

    Link allowing movement outside the planar navigation mesh.
    OffMeshLink component allows you to incorporate navigation shortcuts which cannot be represented using a walkable surface. For example, jumping over a ditch or a fence, or opening a door before walking through it, can all be described as Off-mesh links.
    Tips:
    有小圆圈说明成功创建了

    OffMesh.PNG

    Areas
    在Navigation中添加新的Areas

    Areas.PNG

    NavMeshObstacle
    在场景中添加动态的障碍物
    将场景中新产生的物体设置为寻路中的障碍,默认网格不会重新烘焙,勾选Carve之后会make a cut-out in the navmesh.

    A NavMeshObstacle is cylindrical in shape and can move around the surface of the NavMesh with a specified velocity. By default, the obstacle will only affect the agent's avoidance behaviour rather than the pathfinding. This means that the agent will ignore the obstacle when plotting a path but will sidestep around it while moving along the path. If carving is enabled, the obstacle will create a temporary "hole" in the NavMesh. The hole will be recognised by the pathfinding, so paths will be plotted to avoid the obstacle. This means that if, say, an obstacle blocks a narrow gap, the pathfinding will seek an alternative route to the target. Without carving, the agent will head for the gap but won't be able to pass until the obstacle is clear.

    相关文章

      网友评论

          本文标题:Unity-NaviMesh

          本文链接:https://www.haomeiwen.com/subject/naqiaqtx.html