以前一直用的是漏斗平滑算法,但对于八格子寻路来说,效果其实不是很好,然后coc类游戏的话,就需要更加平滑的路线。于是自己想了一套方案,顺便发现了以前判断直线穿越格子的函数的问题。
先矫正以前的函数:
public bool CheckCanGoForward(Vector3 startPos, Vector3 endPos, int extNum)
{
//init: gather starting location information.
int startCell = GetCellIndex(startPos);
int lastCell = GetCellIndex (endPos);
if(lastCell < 0)
{
Debug.Log("endPos is valid");
return false;
}
float maxDis = (endPos - startPos).sqrMagnitude;
Vector2 dir = new Vector2 (endPos.x - startPos.x, endPos.z - startPos.z);
bool bInBounds = ( startCell >= 0 && startCell < NumberOfCells );
if (!bInBounds)
{
<