public void CalculateObstacle(Bounds bounds)
        {
            if (Config == null || pathfinder == null)
            {
                return;
            }

            grid = pathfinder.GetGrid(Config.GridIndex);

            float tileRadius = grid.TileDiameter / 2;

            Vector3 minPos = new Vector3
                             (
                bounds.min.x - tileRadius,
                bounds.min.y - tileRadius,
                bounds.min.z
                             );
            Vector3 maxPos = new Vector3
                             (
                bounds.max.x + tileRadius,
                bounds.max.y + tileRadius,
                bounds.max.z
                             );

            SAP_TileData minTile = grid.GetTileDataAtWorldPosition(minPos);
            SAP_TileData maxTile = grid.GetTileDataAtWorldPosition(maxPos);

            grid.CalculateColliders(minTile, maxTile);
        }
Example #2
0
        private void Update()
        {
            if (Target != null)
            {
                grid      = pathfinder.GetGrid(Config.GridIndex);
                posInGrid = grid.GetTileDataAtWorldPosition(transform.position).WorldPosition;

                if (transform.hasChanged)
                {
                    isMoving             = true;
                    transform.hasChanged = false;
                }
                else
                {
                    isMoving = false;
                }

                if (GetNextPointDistance < 0)
                {
                    GetNextPointDistance = 0.0001f;
                }

                if (MouseControl)
                {
                    if (Input.GetMouseButtonDown(0))
                    {
                        Target.position = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    }
                }

                if (!CanSearch && changeSearch)
                {
                    StopAllCoroutines();
                    path = null;

                    changeSearch = false;
                }
                else if (CanSearch && !changeSearch)
                {
                    StartCoroutine(FindPath());

                    changeSearch = true;
                }

                if (CanMove)
                {
                    Move();
                }
            }
        }