Prevent Possible Movement Overlapping

Hello, I’m making a game with chess like feel but with movements with a radius limit. The first thing to know is that a piece is called a unit, and they have a limited radius on where they can move. And also their positions should be without decimals. These units have a size of a regular square, they have a default radius of 2, and when pressed would spawn tiles to show the player where it is allowed to move:
image_2023-08-14_090943442

But when the unit has a border or boundary (that has collision) inside it’s intended movement radius, it still is a possible movement square, and worse of all, it can overlap:

image_2023-08-14_091309562

I’m trying a bunch of overly complicated ways like sweep raycasting but they are hard to do.

Here is the Possible movement code:

void Place(Vector3 pos)
{
    MovableSprite sprite = selectedSprite;
    if (hasSelected)
    {
        if (sprite != null)
        {

            float x = Mathf.Abs(pos.x - (int)sprite.transform.position.x) * (1);
            float y = Mathf.Abs(pos.y - (int)sprite.transform.position.y) * (1);
            float net = x + y;
            
            //selectedMinLimit = minRad;
            MeasureLimits(sprite, pos);

            if (net > sprite.MaxRadius)
            {
                Debug.LogWarning($"Object {sprite.gameObject.name} is beyond its limits");
                Debug.LogWarning(sprite.gameObject.name + " has not been placed");
            }
            else
            {
                sprite.Move(pos);
                Debug.Log(sprite.gameObject.name + " has been placed");
            }
            
            selectedSprite = null;
            hasSelected = false;
            sprite.SelectUI(false);
            StartCoroutine(PlacePossibleTiles(false, sprite));
        }
    }
}

And here is the Placement of the Possible Movement Tiles

IEnumerator PlacePossibleTiles(bool place, MovableSprite sprite)
{
    if (place)
    {
        if (sprite != null)
        {
            int x = sprite.MaxRadius * -1;
            int y = sprite.MaxRadius * -1;
            GeneratingSide side = GeneratingSide.BL;
            bool done = false;
            while (!done)
            {
                if (y > sprite.MaxRadius)
                {
                    done = true;
                }

                side = MathUtil.GetGeneratingSide(x, y);

                if ((Mathf.Abs(x) + Mathf.Abs(y)) > sprite.MaxRadius)
                {
            
                }
                else
                {
                    Vector3Int poos = new Vector3Int((int)sprite.transform.position.x - 1 + x,
                        (int)sprite.transform.position.y - 1 + y);
                    possiblePlacesTilemap.SetTile(poos, possibleTile);
                }

                x++;
                if (x > sprite.MaxRadius)
                {
                    x = sprite.MaxRadius * -1;
                    y++;
                }
            }
        }
    }
    else
    {
        possiblePlacesTilemap.ClearAllTiles();
    }

    yield return null;
}

If anyone has an answer, let me know, Thanks.

I’m sure there is a viable way to do the movement this way, however, I would strongly recommend handling movement on a grid like this with data instead of physics. You can simply store each unit’s position as a Vector2, where the X and Y values represent a position on the grid. You can use a Dictionary with a Vector2 as the Key and a Unit as the value to store all the positions of the Units on the grid to make checking if a Unit is already on a grid space as efficient as possible, or simply iterate through all units on the grid comparing their position. If the Vector2 grid coordinates do not contain another Unit (if you want chess-like capturing you can check if the unit is an enemy here) and are not outside the bounds of the grid (i.e. the X and Y values are not greater than the maximum or less than the minimum on the grid), that space can be moved to.

If you want to continue to use physics, my suggestion is to do a Physics2D.OverlapCircle() check on each possible movement tile with a radius less than that of one grid space. This will tell you if there is a collider there.