• Create Account

### #ActualSparkon

Posted 29 October 2012 - 02:33 AM

Something extremely easy would be to keep track of the Y position of the ball and assign that position to the enemy paddle. This will result in an unbeatable AI if you don't reduce the speed of the paddle. Pong does not require an extremely complicated AI, something like this will suffice :


void GetEnemyPosition( const vector2D& ballPosition,vector2D& enemyPosition)
{
if (ballPosition.y < enemyPosition.y )
enemyPosition.y -= speed; // calculated based on the clock
else if (ballPosition.y > enemyPosition.y)
enemyPosition.y += speed;
// if the position is equal the paddle will not move
}

// the += or -= depends on the axis-system you are using, i'm assuming that the origin
// of the system is in the topleft corner.



P.S. If you want to do something else you could try to predict where the ball will hit the wall. Then randomly make the enemyPaddle spin the ball in some random direction.

Excuse my english please

### #3Sparkon

Posted 29 October 2012 - 02:31 AM

Something extremely easy would be to keep track of the Y position of the ball and assign that position to the enemy paddle. This will result in an unbeatable AI if you don't reduce the speed of the paddle. Pong does not require an extremely complicated AI, something like this will suffice :


void GetEnemyPosition(vector2D& ballPosition,vector2D& enemyPosition)
{
if (ballPosition.y < enemyPosition.y )
enemyPosition.y -= speed; // calculated based on the clock
else if (ballPosition.y > enemyPosition.y)
enemyPosition.y += speed;
// if the position is equal the paddle will not move
}

// the += or -= depends on the axis-system you are using, i'm assuming that the origin
// of the system is in the topleft corner.



P.S. If you want to do something else you could try to predict where the ball will hit the wall. Then randomly make the enemyPaddle spin the ball in some random direction.

Excuse my english please

### #2Sparkon

Posted 29 October 2012 - 02:30 AM

Something extremely easy would be to keep track of the Y position of the ball and assign that position to the enemy paddle. This will result in an unbeatable AI if you don't reduce the speed of the paddle. Pong does not require an extremely complicated AI, something like this will suffice :


void GetEnemyPosition(vector2D& ballPosition,vector2D& enemyPosition)
{
if (ballPosition.y < enemyPosition.y )
enemyPosition.y -= speed; // calculated based on the clock
else if (ballPosition.y > enemyPosition.y)
enemyPosition.y += speed;
// if the position is equal the paddle will not move
}

// the += or -= depends on the axis-system you are using, i'm assuming that the origin
// of the system is in the topleft corner.



P.S. If you want to do something else you could try to predict where the ball will hit the wall. Then randomly make the enemyPaddle spin the ball is some random direction.

### #1Sparkon

Posted 29 October 2012 - 02:27 AM

Something extremely easy would be to keep track of the Y position of the ball and assign that position to the enemy paddle. This will result in an unbeatable AI if you don't reduce the speed of the paddle. Pong does not require an extremely complicated ai, something like this will suffice :


void GetEnemyPosition(vector2D& ballPosition,vector2D& enemyPosition)
{
if (ballPosition.y < enemyPosition.y )
enemyPosition.y -= speed; // calculated based on the clock
else if (ballPosition.y > enemyPosition.y)
enemyPosition.y += speed;
// if the position is equal the paddle will not move
}

// the += or -= depends on the axis-system you are using, i'm assuming that the origin
// of the system is in the topleft corner.



PARTNERS