If Distance(Ball_Center, Hole_Center) < Hole_Radius If Distance(Ball_Center, Hole_Center) < Hole_Radius-Ball_Radius ' Ball is completely within the hole. Else ' Ball is more than halfway over the hole. ' Calculate how much of the ball is over the hole, minus the half that doesn't matter. Portion_Over_Hole = Hole_Radius - Distance(Ball_Center, Hole_Center) ' Convert to range 0..1 where 0 means the center of the ball is at the edge of the hole, and 1 means the ball is entirely in the hole, just touching the edge. Tween# = Portion_Over_Hole / Ball_Radius ' Apply cosine to Tween# to model how the ball will fall in faster as more of the ball enters the hole due to the increasing angle of the edge of the ball relative to the edge of the hole. Tween# = 1.0 - Cos(90.0*Tween#) ' Magic happens here. EndIf Else ' Ball is safely outside the hole. EndIf
I haven't quite done all the work for you, but where the magic happens, you need to take that Tween# value, (which will be between 0 and 1, moving more quickly towards 1 as the ball moves further over the edge, using cosine which would be the physically correct way to do it) and use that to scale a force vector which points at the center of the hole, which you would add to the ball's vector. This will cause the ball to slingshot around the edge of the hole if you almost get it in, and you can just stop adding forces and make it dissapear if it ever makes it all the way into the hole.