I might do it with another instance variable on the ball so you know when it is or isn't overlapping the ground by offset. Then you can say if a ball overlaps the ground and variable isn't set, set it and add ball.amount to global. Then in the opposite way if a ball is not overlapping the ground but the variable is set, that means it was overlapping but is now moving away, you subtract ball.amount from global.