静态烘培

导航网格寻路

 

导航网格寻路

 

添加NavMeshAgent组件

导航网格寻路

 

让角色添加脚本控制

导航网格寻路

 

 

   public Transform TraGoals;                             //寻路目标

    private NavMeshAgent _Agent;                           //寻路代理

 

void Start ()

{

        //得到寻路代理

        _Agent = this.gameObject.GetComponent<NavMeshAgent>();

}//Start_end

 

void Update ()

{

     if(TraGoals)

         {

             if (_Agent)

            {

                 //寻找目标

_Agent.SetDestination(TraGoals.transform.position);

            }        

         }

导航网格寻路

 

斜坡与跳跃

导航网格寻路

 

导航网格寻路

 

导航网格寻路

使用Off-Mesh Link组件

 

导航网格寻路

 

导航网格寻路

 

导航网格寻路

添加脚本如下

using UnityEngine;

using System.Collections;

 

public class Tan_Finding : MonoBehaviour {

    public Transform Destnation;

    private NavMeshAgent _NavAgent;

// Use this for initialization

void Start () {

_NavAgent=gameObject.GetComponent<NavMeshAgent> ();

}

 

// Update is called once per frame

void Update () {

        if (Destnation&&_NavAgent)

        {

_NavAgent.SetDestination(Destnation.transform.position);

        }

}

}

网格分层与Navmesh Obstacle组件

只允许通过红桥或者蓝桥

导航网格寻路

 

导航网格寻路

 

导航网格寻路

 

导航网格寻路

 

下图没有勾选Bridge_Blue ,代表选择Bridge_Blue通过

导航网格寻路

 

导航网格寻路

 

网格导航障碍物实验

导航网格寻路

 

脚本控制障碍物如下代码:

  private NavMeshObstacle _Obstacle;

 

// Use this for initialization

void Start () {

        _Obstacle = this.GetComponent<NavMeshObstacle>();

}

 

// Update is called once per frame

void Update () {

        if (_Obstacle)

        {

            if (Input.GetMouseButtonDown(0))

            {

                _Obstacle.enabled = false;

                this.renderer.material.color = Color.green;

            }

            if (Input.GetMouseButtonUp(0))

            {

                _Obstacle.enabled = true;

                this.renderer.material.color = Color.red;

            }

        }

}





相关文章:

  • 2022-12-23
  • 2021-08-05
  • 2021-07-08
  • 2022-01-29
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2017-12-19
  • 2021-05-01
  • 2021-07-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案