How would I move an object towards the mouse but not stick to it.

I want to move a circle around with my mouse but I dont want it to go through walls, how would I achieve this?
For example if its in a box and my mouse moves outside the box, the circle should stay inside the box and not clip through it.

Hey there,

make your circle an object with a collider and a rigidbody. Then in your Update make the circle move towards the mouse position with GetComponent<Rigidbody>().MovePosition(Vector3.MoveTowards(circlePos, mousePos, speed*Time.deltaTime))

This should then take care of collision detection for you.

Let me know if that helped you or if anything is wrong here. Note that i did not test this and you have to adjust variable names and stuff.