前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Unity-NaviMesh

Unity-NaviMesh

作者头像
祝你万事顺利
发布2019-05-29 15:59:29
7610
发布2019-05-29 15:59:29
举报
文章被收录于专栏:Unity游戏开发Unity游戏开发

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

代码语言:javascript
复制
    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.

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019.05.17 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档