2d collisions behaviours end up not working

Hi, I am a complete beginner to Unity. But not to coding.
Anyways, I have a player gameobject, that has a capsulecollider2d and a rigidbody2d.
On the other hand, I have a solidobject that is on a custom layer of objects I want to be able to detect collisions with (it has a tilemapcollider2d and a compsositecollider2d). Here is my hierarchy and the collider boxes :

.

Now here are 2 code samples I’ve tried to use to detect collisions :
First of all : all the variables I’ll use in the 2 methods :

    public LayerMask solidObjectsLayer; // we need to access this in the unity editor

    private InputActions input = null;
    private Vector2 moveVector = Vector2.zero;
    private Rigidbody2D rb = null;
    private float moveSpeed = 0.1f;
    private Animator animator;
    private bool isMoving;

    public ContactFilter2D movementFilter;
    private List<RaycastHit2D> castCollisions = new List<RaycastHit2D>();
    private float collisionOffset = 0.05f;

    private void Awake()
    {
        input = new InputActions();
        rb = GetComponent<Rigidbody2D>();
        animator = GetComponent<Animator>();
    }
private void FixedUpdate(){
  bool collision = PlayerCollision(moveVector);
          if (!collision)
          {
              rb.MovePosition(rb.position + (moveVector * moveSpeed));
          }
          else
          {
              if(PlayerCollision(new Vector2(moveVector.x, 0)))
              {
                  rb.MovePosition(rb.position + (new Vector2(0, -1) * moveSpeed));
              }
              else if(PlayerCollision(new Vector2(0, moveVector.y)))
              {
                  rb.MovePosition(rb.position + (new Vector2(1, 0) * moveSpeed));
              }
          }
}

with the PlayerCollision function being :

 public bool PlayerCollision(Vector2 direction)
{
    int count = rb.Cast(
        direction,
        movementFilter,
        castCollisions,
        Time.fixedDeltaTime * moveSpeed + collisionOffset
        );

    if (count != 0)
    {
        Debug.Log("Collision");
        return true;
    }

    return false;

}

This first solution ended up laggy : on edges of the collider, my system of making the character move on the right if he’s under or above the structure makes the screen shake and when it reaches the end of the structure, it gets inside of it and crosses it entirely until being under it (if he was above it).

The second one :

private void FixedUpdate(){
  if (isWalkable(playerPos))
  {
      rb.MovePosition(rb.position + (moveVector * moveSpeed));
  }
}

With the isWalkable function being :

private bool isWalkable(Vector3 targetPosition)
{

    if(Physics2D.OverlapCircle(targetPosition, 0.2f, solidObjectsLayer) != null)
    {
        return false;
    }
    return true;
}

This method detects collisions just fine. But I end up being stuck in them. It seems like it is the best one because it doesn’t make my screen shake or doesn’t create weird “going through solid objects”.
Would there be any way to unblock the player ? I mean without checking where he collided and just teleporting him back. Some proper way of making him slide on the structure or just leave it by going in another direction.

Thank you so much by advance for your help, I’ve spent a lot of time on this and can’t seem to find a solution.