Bounding 2D Top Down

I’m currently developing a top down 2D shooter in the style of asteroids. I need to be able to make maps the player traverses in a linear fashion going from one encounter to another. So I need to make areas where the player can fly, and the player can’t fly, and I’m not sure of the best way to do this in 2D with Unity. My first thought was to lay out out a collection of Colliders, making a more complex map out of simple shapes (Spheres, Rectangles, etc.) and when the player is no longer within the boundaries of any Collider then we know he is out of bounds and should be able to fly no further in that direction. So in psuedo code it might look something like this.

ArrayList<Collider> boundaries;

void OnTriggerEnter(Collider other)
{
    if(other.tag == "boundary")
    {
        if(!boundaries.contains(other)
        {
                boundaries.add(other);
        }
    }
}


void OnTriggerExit(Collider other)
{
    if(other.tag == "boundary")
    {
        if(boundaries.contains(other)
        {
                boundaries.remove(other);
        }
    }
}

void Update()
{
    if(boundaries.size() != 0)
    {
        //Move player forward in current direction
        if(boundaries.size() == 0)
            //Move player back in bounds to previous location.
    }
}

This code will keep the player in bounds. However, I would like the player to sort of slide against the boundary walls when he reaches them, and with this code, he’ll just stop dead in his tracks. Kind of getting stuck against the wall.

Any suggestions?

If you are using rigidbody physics for this then the player will stop when he makes contact with a wall but will also be able to slide along it. You can adjust the friction properties of the colliders’ physics materials to make them extra slippy if you need to.

Yeah the problem is I’m using Colliders to represent the areas in which a player can move. Is there any way to get rigid body physics to work only at the edges of Colliders so the player can fly around inside of them, but can not exit them?