Object collision

I’m really new to Unity, so bear with me please.

I have an object in my scene that is controlled by the user (using WSAD). The object is a sphere, and it’s inside a rectangular enclosure. I want to know of there’s a way I can prevent the sphere from going outside the walls of the enclosure, but still be able to control the movement of the sphere with WSAD.

Making the walls into mesh colliders and making the sphere a rigidbody didn’t work, but I’m not really sure what I’m supposed to do

There are a couple of way you could do this.

One way would be to make the walls box colliders, and the ball a sphere collider, and have the WASD keys add force to a rigidbody, or use the character controller.

Thanks a lot! Adding force to the rigidbody worked!

Though if I keep pressing the key in the direction towards the wall, it will continue through the wall anyway, is there a way to prevent that?