I faced this problem a few weeks ago and here is my solution
Code:
private void centerShooter() {
ColorImage image = null;
BinaryImage thresholdImage = null;
BinaryImage bigObjectsImage = null;
BinaryImage convexHullImage = null;
BinaryImage filteredImage = null;
int biggestindex = 99;
int widest = 0;
int highest = 0;
ParticleAnalysisReport[] reports = null;
try{
image = camera.getImage();
thresholdImage = image.thresholdRGB(0, 25, 20, 225, 0, 225);
// thresholdImage.
bigObjectsImage = thresholdImage.removeSmallObjects(false, 2);
convexHullImage = bigObjectsImage.convexHull(false);
filteredImage = convexHullImage.particleFilter(cc);
reports = filteredImage.getOrderedParticleAnalysisReports();
for (int i = 0; i < reports.length + 1; i++ ){
if ((reports[i].imageHeight > highest) && (reports[i].imageWidth > widest))
{
widest = reports[i].imageWidth;
highest = reports[i].imageHeight;
biggestindex = i;
System.out.println("Problem's not here");
}
System.out.println("Test");
SmartDashboard.putString("Filtered Image", filteredImage.toString());
outputstring = "Height = " + reports[biggestindex].toString() + "Width = " + reports[biggestindex].toString();
System.out.println (outputstring);
SmartDashboard.putString("Dimensions: ", outputstring);
SmartDashboard.putInt ("Targets Found", reports.length);
SmartDashboard.putInt("height of Target", reports[biggestindex].imageHeight);
SmartDashboard.putInt("Width of Target", reports[biggestindex].imageWidth);
if(reports[biggestindex].center_mass_y>centerdown){
increaseShooterAngle();
Timer.delay(.3);
shooterAngle.set(Relay.Value.kOff);
System.out.println("Increase");
}else if(reports[biggestindex].center_mass_y<centerup){
decreaseShooterAngle();
Timer.delay(.3);
shooterAngle.set(Relay.Value.kOff);
System.out.println("Decrease");
}else{
System.out.println("You're Good");
}
if(reports[biggestindex].center_mass_x>centerleft){
toTheLeft();
}else if(reports[biggestindex].center_mass_x<centerright){
toTheRight();
}else{
tank.tankDrive(0, 0);
}
}
}catch(Exception ex){
//System.out.println("Failed");
SmartDashboard.putString("Error", ex.getMessage());
}finally{
}
try{
filteredImage.free();
convexHullImage.free();
bigObjectsImage.free();
thresholdImage.free();
image.free();
}catch(NIVisionException ex){
}
}
This still isn't perfect, as most times the robot completely misses the vision target, a problem that I must face today, and this code likes to also track white light... no explanation needed

and in terms of the Y axis tracking, you may want to have a sensor that can tell you the angle of the shooter and have the shooter move until it is at the right angle.