Help player movement for android and player passing throug objects

I’m making a small game for myself and I’m struggling to find a solution to a problem:
When I make a black obstacle with tag “Obstacle” the player pass through it but the player cannot move through the barrier that have the same tag
In this video the blue one pass through the barriers while the red can’t

The CheckMovement function should give me true if there’s no “Obstacle” tag objects in the direction I’m going and if there is don’t move the player but sometimes it doesn’t work like in the video while I can set my player position inside other objects

using System;
using UnityEngine;
using UnityEngine.SceneManagement;

public class PlayerMovement : MonoBehaviour
{
    private Vector3 startPos, endPos;
    [SerializeField] private LayerMask mask;
    [SerializeField] GameObject redPlayer;
    [SerializeField] GameObject bluePlayer;
    private Vector3 pos;

    void Update()
    {
        CheckPlayerPos();
        if (Input.GetMouseButtonDown(0))
        {
            startPos = ClickedPoint();
        }
        if (Input.GetMouseButtonUp(0))
        {
            endPos = ClickedPoint();
            Vector3 distance = endPos - startPos;
            if (distance.z > 0 && Mathf.Abs(distance.z) > Mathf.Abs(distance.x))
            {
                Debug.Log("Top");
                pos = Vector3.forward;
                MovePlayers();
                return;
            }
            else if (distance.z < 0 && Mathf.Abs(distance.z) > Mathf.Abs(distance.x))
            {
                Debug.Log("Bot");
                pos = Vector3.back;
                MovePlayers();
                return;

            }
            else if (distance.x < 0 && Mathf.Abs(distance.z) < Mathf.Abs(distance.x))
            {
                Debug.Log("Left");
                pos = Vector3.left;
                MovePlayers();
                return;
            }
            else if (distance.x > 0 && Mathf.Abs(distance.z) < Mathf.Abs(distance.x))
            {
                Debug.Log("Right");
                pos = Vector3.right;
                MovePlayers();
                return;
            }
        }

    }

    private void CheckPlayerPos()
    {
        if (redPlayer.transform.position.y < 0 || bluePlayer.transform.position.y < 0)
            SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    }

    private void MovePlayers()
    {
        if (CheckMovement(redPlayer.transform.position))
            redPlayer.transform.position += pos;
        if (CheckMovement(bluePlayer.transform.position))
            bluePlayer.transform.position -= pos;
    }

    private bool CheckMovement(Vector3 playerPos)
    {
        Vector3 tempPos = playerPos + pos;
        Collider[] fromPos = Physics.OverlapSphere(tempPos, .25f);
        foreach (Collider collPos in fromPos)
        {
            if (collPos.CompareTag("Obstacle"))
            {
                return false;
            }
        }
        return true;
    }

    private Vector3 ClickedPoint()
    {
        Vector3 pos = Vector3.zero;
        var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit = new();
        if (Physics.Raycast(ray, out hit, Mathf.Infinity, mask))
        {
            pos = hit.point;
        }
        return pos;
    }
}

The code used for swiping and move the player is this but is really inaccurate. Since I’m making a 3D isometric game with movement based on screen swipe (Mobile) this works but sometimes I get the wrong input

if (Input.GetMouseButtonDown(0))
        {
            startPos = ClickedPoint();
        }
        if (Input.GetMouseButtonUp(0))
        {
            endPos = ClickedPoint();
            Vector3 distance = endPos - startPos;
            if (distance.z > 0 && Mathf.Abs(distance.z) > Mathf.Abs(distance.x))
            {
                Debug.Log("Top");
                pos = Vector3.forward;
                MovePlayers();
                return;
            }
            else if (distance.z < 0 && Mathf.Abs(distance.z) > Mathf.Abs(distance.x))
            {
                Debug.Log("Bot");
                pos = Vector3.back;
                MovePlayers();
                return;

            }
            else if (distance.x < 0 && Mathf.Abs(distance.z) < Mathf.Abs(distance.x))
            {
                Debug.Log("Left");
                pos = Vector3.left;
                MovePlayers();
                return;
            }
            else if (distance.x > 0 && Mathf.Abs(distance.z) < Mathf.Abs(distance.x))
            {
                Debug.Log("Right");
                pos = Vector3.right;
                MovePlayers();
                return;
            }
        }

This is what I would like to achieve

That seem to be two questions, I’d recommend maybe making a separate thread for the touch input problem.
Regarding the first issue, I noticed one thing: in MovePlayers, you change the player positions by adding / subtracting pos, but in the CheckMovement method you only add pos.

That might explain why the blue one can go out of bounds but not the red one, what about the red going inside the obstacles then? Same problem?

For the CheckMovement I can use a bool to check if is red or blue square

Hard to diagnose from here, the obstacles do have colliders set up and are tagged correctly?
I think you could also ditch the OverlapSphere thing and instead do a raycast from the player positions in the respective directions and limit the raycast length to one tile length.
Anyway, adding Debug.Log(); calls to check what is happening for which positions and directions might be a good way to understand what’s going on (and wrong).

Or (if you stick with OverlapSphere) just do CheckMovement(bluePlayer.transform.position - pos) and CheckMovement(redPlayer.transform.position + pos) and not add pos in the check method.

They have the same tag as the outside walls and it sometimes work, unfortunately it didn’t in this video. I could check it later