我们常见的有三种寻路方式
1.路点寻路
2.单元格寻路
3.网格寻路
简单介绍一下
1.路点寻路 如下图,物体从 point位置出发依次经过(point1 、point2、point3、point4、point5)进行移动
代码如下
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WayPointPath : MonoBehaviour {
//所有路点的父物体
private Transform point_parent;
private int k=0;
// Use this for initialization
void Start () {
//获取路点的父物体
point_parent = GameObject.FindWithTag("Way").transform;
}
// Update is called once per frame
void Update () {
PointToPoint();
}
//物体按照路点移动
void PointToPoint()
{
//判断物体到下一个路点的距离
if (Vector3.Distance(transform.position, point_parent.GetChild(k).position) > 1f)
{
//用Vector3.Lerp移动
transform.position = Vector3.Lerp(transform.position, point_parent.GetChild(k).position, 0.1f);
}
else
{
k=(k+1)%point_parent.childCount;
}
}
}
2.单元格寻路,
A*算法插件

本文介绍了Unity3d中的NavMeshAgent组件用于自动寻路的方法,包括路点寻路、烘焙网格以及寻路参数设置。通过设置寻路区域、烘焙静态物体、调整寻路属性,可以实现游戏物体的智能导航。同时,文章提到了寻路区域的Cost值影响寻路路径的选择,以及如何通过代码控制寻路区域。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



