Beispiel #1
0
        public bool GetCell(float x, float y, float z, out Cell cell, out float resultY)
        {
            cell    = null;
            resultY = 0;

            //if true then no result
            if (empty || _mapCell == null)
            {
                return(false);
            }

            float scale = PathFinder.gridSize / PathFinder.CELL_GRID_SIZE;

            List <Cell> mapChunk = _mapCell
                                   [Mathf.Clamp((int)((x - chunk.realX) / scale), 0, PathFinder.CELL_GRID_SIZE - 1)]
                                   [Mathf.Clamp((int)((z - chunk.realZ) / scale), 0, PathFinder.CELL_GRID_SIZE - 1)];

            float sqrDist = float.MaxValue;

            //search cell in chunk are inside chunk
            if (mapChunk.Count > 0)
            {
                for (int i = 0; i < mapChunk.Count; i++)
                {
                    float curCellY;
                    //see if this point are inside cell and get position if are
                    if (mapChunk[i].GetPointInsideCell(x, z, out curCellY))
                    {
                        float curDiff = SomeMath.Difference(y, curCellY);
                        if (curDiff < sqrDist)
                        {
                            sqrDist = curDiff;
                            cell    = mapChunk[i];
                            resultY = curCellY;
                        }
                    }
                }
            }

            return(cell != null);
        }