Right now I'm working on a pong clone game and the AI I want is pretty simple, if the ball is above the paddle, the paddle moves up and reverse. What I have is this:
if(ball.getY() < y - height/2){
moveUp();
}
if(ball.getY() > y + height/2){
moveDown();
}
What's happening is the paddle looks like it's spazzing out, it alternates between going up and down like every .5 seconds, but still travels in the general direction it's supposed to go.
moveUp and moveDown affect the y variable right? In that case you may want to make it so that only one of those functions is called each time (possibly by turning the moveDown if statement into an else-if statement)
#1 question before anyone should EVER bother helping you: Have you traced the execution of your code? If so, what happens? If you find it, you will know what your problem is and likely not need anyone else to do it for you.
The ai paddle is probably spazzin out because each frame, when the paddle catches up to the ball, it goes too far up/down and in the next frame has to go back down/up. So instead of moving the opponent at a constand speed/frame, it should move by the difference between the position of the ball and center of paddle. Example: move by ballY - paddleY, if difference is greater than the max speed the paddle can go, put it as max speed.