Hello,
I'm finished with my two player pong game. I have no idea how to make a computer to follow the label towards the ball... does anyone know how?
I searched up examples and tried figuring it out but their code was very confusing :confused:
Printable View
Hello,
I'm finished with my two player pong game. I have no idea how to make a computer to follow the label towards the ball... does anyone know how?
I searched up examples and tried figuring it out but their code was very confusing :confused:
Moved to Games and Graphics.
How so?Quote:
Originally Posted by paralinx
Just make the paddle's vertical position equal to the ball's vertical position and you can never lose. :)
If you are going to limit the speed of the computer's paddle then the simplest method is to test if the ball is above or below the paddle and then move the paddle in the appropriate direction.
This does make it difficult to deal with balls that have a high vertical speed.
Another option is calculate the path of the ball, where it bounces off the walls and where it will cross the paddle's path.
Then you place the paddle there and wait for the ball.
This is for defensive AI.
Offensive AI would need to decide how to play the ball back to the player.
Will it go fast and straight?
Will it bounce up and down rapidly?
That shouldn't be too hard. In each loop cycle, simply subtract the paddle's Yval by the Ball's Yval. If the value is negative, move the paddle up, and if the value is positive, move the paddle down (assuming the scale is with 0,0 on the top left corner). The most advance AI will keep with the ball exactly (although that would make it actually impossible to beat), and a lesser difficulty will have a slower moving paddle, or not start calculating until the ball is halfway towards them or something like that.
This is how i would do it.
VB Code:
DAmount = ball.top - paddle.top if DAmount <0 then paddle.top = paddle.top - 10 elseif DAmount >0 then paddle.top = paddle.top + 10 end if
Or just:
paddle.top = ball.top
:)
not a great method because the paddle would appear to jump at the start!Quote:
Originally Posted by jeroen79
That's a matter of setting things up properly.
yea, but evan so its not the best method in the world :) no offence intended its just clumsy programming
Pino
How is it clumsy?
You want the paddle to follow the ball.
This will make it do just that with minimal effort.
Of course, this will make the game very un-fun as you can't beat the AI.
But that is a different thing.
It is clumsy as it does not take into account things such as the speed of the bat, size of the bat/ball, time to change direction, prediction of ball position, etc.
As you pointed out, it would also be no fun to play against. ;)
Actually, it doesn't need all those things.
The difference with other methods is that this one assumes total and direct control over the bat's position.
Other methods have direct and total control over the bat's position but can merely control the speed (up to a limit) and direction of the bat
So the 'clumsy' method would be suited for the gods while us mere mortals have to do with other methods of control.
Just to illustrate that in some cases lesser performance actually requires more work in software.
That was incredibly vague, what the heck are you talking about?