Unity-NaviMesh

博客介绍了Unity寻路系统的设置与组件应用。包括对可寻路场景物体进行Navagition烘焙,设置为静态并修改区域和权重;给物体添加NavMeshAgent,引入命名空间;还介绍了OffMeshLink、NavMeshObstacle组件的作用及使用方法,如添加动态障碍物等。

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:
有小圆圈说明成功创建了

11173460-73278651e23eb0e2.PNG
OffMesh.PNG

Areas
在Navigation中添加新的Areas

11173460-897dcb10cb7574d6.PNG
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.

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值