Pong Help [Archive] - C Board

PDA

View Full Version : Pong Help


Shadowwoelf
06-29-2007, 02:43 AM
I Can't seem to figure out how to make the computer pong AI actually beatable. Computer.y=Ball.y;

if(Computer.y>2.87){
Computer.y=2.87f;
}
if(Computer.y<-3.62){
Computer.y=-3.62f;
}

Thats pretty much my AI right there. Only problem is that it never actually loses. I tried some other variations like if its lower or higher then move it up or down .01f; with some random movement but that doesn't help.

SO how do I balance out the AI?

Also if you need my entire coding just ask

Thanks for reading, hope to hear from you soon

Salem
06-29-2007, 03:48 AM
Well you're making it track the ball all the time, so obviously the bat will always meet the ball.

Suggestions
- limit the lateral acceleration of the computer bat.
- only track the ball position when the ball is on the computer side of the net (otherwise just move randomly). For more realism, pick a random point past the net to mimic reaction times.

Shadowwoelf
06-29-2007, 02:10 PM
Thanks I just limited the lateral acceleration and I made it only follow the ball when its on a random point near its side of the field.

if(Ball.x<=-((rand()%100+1)/1000)){
if(Computer.y<Ball.y){
Computer.y+=.005f;
}
if(Computer.y>Ball.y){
Computer.y-=.005f;
}
if(Computer.y>2.87){
Computer.y=2.87f;
}
if(Computer.y<-3.62){
Computer.y=-3.62f;
}
}