Jump to content
  • Advertisement
Sign in to follow this  
Ekim_Gram

Better AI for Pong than just following the ball?

This topic is 4833 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

I'm just wondering, is there a better way to program some AI for a simple Pong clone than simply having the automated paddle follow the game ball once it gets to a certain point on the playing field?

Share this post


Link to post
Share on other sites
Advertisement
Of course, just predict exactly where it crosses your "paddle line" and go straight there. If you allow the paddle to actually controll the ball's direction, then you also want to direct the ball to the point firthest from your opponent's paddle. It is a very easy game to make perfect AI for, the reason you don;t do it is that the game is pointless then.

Share this post


Link to post
Share on other sites
When I wrote pong last, I used some spiffy linear algebra to extrapolate exactly where the ball will be when it crosses into the goal threshold (given its current position and velocity), so given that value the AI can just mosey on over.

To make it not-impossible, I threw in some "rounding error" variations which occasionally (pretty rarely, actually) made the computer miss it slightly when the ball was travelling at high speed, angle (or both). It was an undocumented feature [wink]

Share this post


Link to post
Share on other sites
Make the AI a little slow to react. Have a delay of .5 seconds after the player hits the ball before the AI moves at all. Then when the AI does move, force them to move slowly at first, and speed them up over time (maybe a full second until the AI can move at full speed). Combine that with an error-prone prediction algorithm that those guys are talking about, and you'll have a pretty fun AI.

Share this post


Link to post
Share on other sites
I made a simple pong where the ball direction was governed by where it hit the bat. No big deal but you could aim the ball away from the opponents bat.
In that situation, as soon as the AI hit the ball, it moved back towards the centre as a tennis or squash player would and waited to see in what direction the ball was returned (OK, really it THEN just followed the ball).
The AI would also aim to get return the ball as far from the player as possible with a slight bias to their current direction.
The next step was to add a slight speed reduction when a player changes direction but I lost interest.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

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!