Jump to content
• Advertisement

Public Group

# Help fix pong enemy paddle please?

This topic is 2378 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

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.

#### Share this post

##### Share on other sites
Advertisement
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.

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5
• Advertisement

• 11
• 13
• 87
• 11
• 10
• ### Forum Statistics

• Total Topics
632973
• Total Posts
3009615
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!