Instantiated objects get "stuck" (Physics)

I have a simple Orthographic scene with some random fixed objects and a ground “hill” object. I have it setup so you can click on the screen and if there is no collider at that point, it instantiates a little ball that bounces around the objects and gets destroyed when it falls/rolls off the hill.

The problem is that if I click really REALLY close to the ground, it will instantiate the ball but the ball will be “stuck” halfway into the ground and won’t move. Sometimes it will fling the object out from the ground which is fine for this particular purpose but I’d like to fix the ball getting stuck issue but am unsure how to go about that since I’m just using the default physics engine.

Any suggestions?

Without you code, I have to guess a bit.

  • You say “if there is no collider at that point.” I assume that means you are doing a Raycast() based on the mouse position. You could replace that with a Physics.SphereCast() with the radius of the ball as the radius of the SphereCast().
  • If the game is 2D, or if you always instantiate at the same distance from the screen, you could do a Physics.CheckSphere() in addition to the raycast.
  • Your instantiated object could do a Raycast() for the ground in Start(). If the ground is too close, it could lift itself up to clear the ground.