我们常见的有三种寻路方式
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*算法插件
</