Moving within the boundaries

Image visible room, all this is done in 2D, when I Spit finger to the ball - I can move it within the room. I need to do to get the ball so intermixed within the room, but if I try to drag it beyond it abuts the wall and will move along the wall as well as my finger abroad room. How to implement this?

I would implement a boolean variable of if you’re dragging the ball or not, then instead of setting the ball’s position to the mouse’s position, I would have it set to adding force toward the mouse. That way while you’re dragging it, it will be constantly going “toward the mouse” however if a collider is in the way, it will stop it.

more options

move the ball by first getting the fingers position in a variable and then clamp the values of that variable according to where your walls are, then set your balls position to be the value of your clamped variable