Top down 2D collision: How do I prevent players from getting "stuck" in walls?

In my game, the player moves using velocity until they run into a collider (Up, down, left or right). They cannot redirect their movement once moving. However, if they are directly touching a collider, they can move into it (again) and get “stuck” in the wall, unable to move again because it reads as moving.

Using a Raycast does not seem to work because if the player is already touching a wall, their collider is already slightly inside of it and it seems to ignore the collider. Currently, I am using a bool to check whether or not the player just moved in a specific direction, essentially preventing them from moving in the same direction 2 times in a row. However, if they run into a corner, this problem can still occur.

Is there any way to check the direction of a collision? Or a simple solution to this problem? I am in the process of learning C# and would greatly appreciate some assistance. Thanks in advance!

Why not try this?
Once the object hits a wall, set the movement speed to 0 from within the script. and make sure that the mass of the walls are big… something like 99999 could to it. That is, if you don’t mean them to move or anything. and if there is no gravity. Hope this helps

first of all are you using a box/colliders/cirkel/colliders?

if you are using a box colliders this should fix all youre problmes if you go to youre rigidbody and change the collision detections to continuous this will take more computer power but it will also make the collision detections work better

if you are a using a cirkel collider the problem could be that the edges of the cirkel colliders are getting stucked in walls which i personnaly solved by using a mix of box colliders and cirkel colliders to remove the edges of the top of the cirkel i can send a picture if you need