Pong: How does the paddle know where the ball will hit?
Posted
by
Roflcoptr
on Stack Overflow
See other posts from Stack Overflow
or by Roflcoptr
Published on 2011-01-02T09:19:02Z
Indexed on
2011/01/02
9:53 UTC
Read the original article
Hit count: 358
After implementing Pacman and Snake I'm implementing the next very very classic game: Pong.
The implementation is really simple, but I just have one little problem remaining. When one of the paddle (I'm not sure if it is called paddle) is controlled by the computer, I have trouble to position it at the correct position.
The ball has a current position, a speed (which for now is constant) and a direction angle. So I could calculate the position where it will hit the side of the computer controlled paddle. And so Icould position the paddle right there. But however in the real game, there is a probability that the computer's paddle will miss the ball. How can I implement this probability?
If I only use a probability of lets say 0.5 that the computer's paddle will hit the ball, the problem is solved, but I think it isn't that simple.
From the original game I think the probability depends on the distance between the current paddle position and the position the ball will hit the border.
Does anybody have any hints how exactly this is calculated?
© Stack Overflow or respective owner