Do you have a way to tell the angle and height of the camera? If so, you know the height of the tallest goal, and the angle relative to the camera, so you can use tangent to figure it out. Something like this:
Code:
distanceToTarget = (targetHeight-cameraHeight)/tan(cameraAngle+relativeTargetAngle);
I used a similar height-based algorithm last year and had the same sort of problem with error. I found this angle-based formula by looking at Miss Daisy's vision code from last year.