Circle Collider 2d is slipping off box colider2d when it shouldnt

I have a crude rectangle sprite with a box colider 2d, and a circle sprite with rigidbody 2d and circle collider 2d, as seen in the image below. When I click on the red rectangle, it moves up fairly quickly a little more than the diameter of the circle.

If this occurs from the position show, or with the circle any further right than it currently is, the circle appears to fall down onto the yellow box almost instantly, hugging the side of the red rectangle. If I let the circle go a little more onto the red rectangle then it is pushed up correctly. Why is the circle falling off the red rectangle from this position, and how can I prevent it from acting like this?

You should try to step back and think more about what you’re asking the physics system to do. It sounds like you’re simply repositioning stuff via the Transform. This means you instantly move a collider from one position to another. In the case above, instantly moving the “red rectangle” which I presume has a collider on it means you cause it to overlap the “circle”. You have forced an overlap which the physics system has solve. The solver works by moving the “circle” away from the “red rectangle” using the shortest exit which is probably to the right.

If you are moving colliders then you should always attach a Rigidbody2D otherwise the collider is static (non moving). If you don’t want forces applied to your collider then use a Rigidbody2D set to be Kinematic else use Dynamic.

In the case above, it sounds like your “red rectangle” should have a Kinematic Rigidbody2D. After you’ve added this, instead of modifying the Transform which you should never do, use Rigidbody2D.MovePosition which moves the body from its existing position to the specified one during the next physics update. It’s also compatible with Rigidbody2D interpolation meaning you’ll get smooth movement during the frame update. More importantly, it means the “circle” will contact the top of the “red rectangle” during its move upwards and so should get forces applied to it which should move it upwards as well asssuming the “circle” has a Dynamic Rigidbody2D attached.