How to prevent 2d objects go over each other?

Hello. I don’t know if the title is clear so I’m uploading an image to make it easy to understand what I’m trying to do 152228-soru.gif I’m making a checkers like game in order to learn with practice.

I have my 2D objects, moving with raycast. Basically teleporting to the point where mouse clicks. Yet I don’t want them to go over each other but I want them to be have to go around.

void posOfClick()
    {
            Vector3 mousePos = Input.mousePosition;
            mousePos.z = 10;
            Vector3 screenPos = Camera.main.ScreenToWorldPoint(mousePos);
            RaycastHit2D hit = Physics2D.Raycast(screenPos, Vector2.zero);

        if (hit)
        {
            orgPos = (gameObject.transform.position);
            tilePos = (hit.transform.position);
            transform.Translate(tilePos.x-orgPos.x, tilePos.y-orgPos.y, 0);
        }
    }

This is how my teleporting system works. Thanks in advance.

So you don’t want the piece to move at all if there is another piece in the way? There are a couple ways you can do this

1 - If your game truly is a grid, you can keep track of which tiles are occupied by pieces. Whenever you want to move a piece, you can check which tiles the piece has to travel through and if those tiles are occupied or not. If you don’t already have a system that keeps track of which pieces are on which tiles and vice-versa this will be a harder solution to write but probably something that will benefit you down the road.
**
2 - If you don’t want to do this, you could simply put the pieces on their own layer, then do a raycast from the current position to the new position before you move the piece and see if there is anything in the way. Easier solution to write, but probably not the correct way to tackle the problem if you are making a grid-based game like checkers