How to make an object follow the mouse but only to a certain point on screen?

I’m making a 2D game where a basketball hoop with collisions follows the mouse to catch basketballs.
My problem is that on certain levels, I need the basketball hoop to stop following the mouse at the boundaries. I tried using clamping on the x and y, but that only visually stops it. The basketballs still collide with where it should be because it is rapidly moving back and forth between the mouse and boundary. Any help is appreciated.

are you using FixedUpdate() or Update()?