im just starting to work on AI things and i started with a pong game...
i came up with a system that every time the ball hits a wall or a paddle it calls the alert() method of the AIController class.
the problem is the paddle always reaches and hits the ball the first time, then seems to move in crazy direction and will never hit another shot...
heres what i got so far:
the paddle attempst to predict where the ball will intercept the y-axis and calculate the speed it will need to move to get to the other side but it doesnt really work too well and i cant figure out why....
any ideas?
thanks,
ken
i came up with a system that every time the ball hits a wall or a paddle it calls the alert() method of the AIController class.
the problem is the paddle always reaches and hits the ball the first time, then seems to move in crazy direction and will never hit another shot...
heres what i got so far:
Code:
public void alert() { //set path based on the balls anticipated y-intercept if(controlLeft) { System.out.println("Left Pad AI ALERTED"); //find the distance that needs to be travelled int distanceX, distanceY; distanceX = ballX-leftPadX; distanceY = (int)(ballY-leftPadY-((.5)*leftPadHeight)-(.5*ballSize)); double timeX = distanceX*1.0/ballSpeedX; double timeY = distanceY*1.0/ballSpeedY; if(timeY<timeX) mySpeed = (distanceY)/Math.abs(distanceY); else mySpeed = (int)(distanceY*1.0/timeX); } }
any ideas?
thanks,
ken
Comment