• Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

### #1stein102  Members   -  Reputation: 281

Like
0Likes
Like

Posted 16 April 2012 - 08:19 PM

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.

### #2Trienco  Members   -  Reputation: 1300

Like
1Likes
Like

Posted 16 April 2012 - 09:47 PM

Of course it is. Put a breakpoint in there when it does that and you might notice that the ball is above the paddle, then the paddle moves and is above the ball, so the next frame it will move down again and on and on and on.

A concept you might want to look up is called Hysteresis (IF you really want to keep that approach).

Even if you add an area where the paddle doesn't move it won't look very natural to constantly stop-move-stop, because a real player estimates where the ball WILL be when it reaches him. AI can easily calculate that, add a random error and simply move to that position. To look more like a human player, the calculated position can be adjusted every once in a while as the ball gets closer and the random error gets smaller.
f@dzhttp://festini.device-zero.de

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS