Sign in to follow this  

Pong Clone Help

This topic is 3846 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 have made a C++ pong clone. However I don’t know how to make AI. What do I need to do in code so that the AI paddle goes after the ball? Does anyone know a specific tutorial or example code for this? Many thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by Shwanger
you could also make the paddle be only to move after a certain amount of time... otherwise it will be impossible to beat if you match the paddle to the ball movement...


Not really, the paddle should never move faster than what the player can move, thus it would come into situations where the ai-paddle can't keep up.

My pong clone only moved the AI when the ball headed towards him, but this can be tweaked back and fourth, you can set a limit on the screen where the AI can 'see' the ball and react to it.

Share this post


Link to post
Share on other sites
When the ball goes towards the opponent, move the paddle to the center.

After the opponent has touched the ball:

- medium difficulty: move the paddle towards the ball as already suggested.
- hard difficulty: precalculate where the ball will end and move the paddle to that position.

P.S.: impossible difficulty is: while the ball goes towards the opponent, precalculate where the ball will end in the opponent's side, then calculate all the possible trajectories of return (taking into account any receiving position of the opponent's paddle) and move the paddle to the center of the most probable returning positions.

Share this post


Link to post
Share on other sites

This topic is 3846 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this