Esempio n. 1
0
    IEnumerator FindFlockingPath()
    {
        float updateTime = 1 / maps[0].map.updateFrequency;
        var   path       = new List <Vector2Int>();

        while (true)
        {
            currentPos = grid.WorldToGrid(transform.position);
            //var pos = Flocking(); // Use updateTime to scale next position? Use current-time calculation?
            if (flockPoint.HasValue)
            {
                var gridPos = grid.WorldToGrid(flockPoint.Value);
                path = InfluenceMapNavigation.FindMax(maps, currentPos, searchDistance, gridPos, flockingInfluence);
                if (path.Count > 0 && path[path.Count - 1] == gridPos)
                {
                    flocking = true;
                }
                else
                {
                    flocking = false;
                }
            }
            else
            {
                path     = InfluenceMapNavigation.FindMax(maps, currentPos, searchDistance);
                flocking = false;
            }
            newPath = path;
            yield return(new WaitForSeconds(updateTime));
        }
    }
Esempio n. 2
0
 protected IEnumerator FindPath()
 {
     while (true)
     {
         currentPos = grid.WorldToGrid(transform.position);
         var maxPath = InfluenceMapNavigation.FindMax(maps, currentPos, searchDistance);
         if (maxPath != null && maxPath.Count > 0)
         {
             newPath = maxPath;
         }
         yield return(new WaitForSeconds(1 / maps[0].map.updateFrequency));
     }
 }