# Pong Physics

This topic is 4572 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

This is a very basic question, but I am designing my first game (Pong) and I am having a hard time coming up with a good deflection model for the ball. At the bare minimum it will change x-direction when it hits the paddle, or it might deflect more in the y-direction when it hits near the edges, but I was wondering if there were any more interesting models that I could look into. Any suggestions would be appreciated, thanks!

##### Share on other sites
Well, at the very minimum you could do 8 directional reflection easily (ignoring the two directions along the vertical axis). If you assume up is direction 1 and go clockwise at 45 degree increments your movement is something like:
Dir 1 - Y movement = Speed, X movement = 0
Dir 2 - Y movement = X movement = Speed/square root of 2
Dir 3 - Y movement = 0, X movement = Speed
Dir 4 - Y movement = -Speed/sqrt(2), X movement = Speed/sqrt(2)
Dir 5 - Y movement = -Speed , X movement = 0
etc...

So if the ball hits the top wall moving at in direction 2 then the simple reflection changes its direction to direction 4. You can also determine which direction the ball comes off of the paddle based on where it hits paddle (assume paddle on right side of the screen): Hits at top -> Direction now = 8, Hits in middle -> Direction = 7, Hits at near bottom -> Direction=6. This is a very simple example but can still be interesting to play, especially if the ball speed changes as well.

##### Share on other sites
Note: This assumes your paddles are on the left and right sides of the screen and move vertically:

The basic reflection in pong is pretty standard. You just reverse the x-velocity. That way, the ball bounces off the paddle at the same angle it hits it from, which is what would really happen.

For a little variety, you could try the following:

If the paddle is moving up when the ball hits, also add to the upwards y-velocity of the ball when it bounces, as if the paddle were transferring momentum to the ball. Similarly, if the paddle is moving down when the ball hits, also add to the downwards y-velocity of the ball when it bounces.

This method allows players to "add spin" to the ball, making it harder for their opponents to predict where the ball is by adding to its vertical velocity, or "reduce spin" by subtracting from its vertical velocity and make it easier for themselves.

Additionally, if the paddle is not moving when the ball hits it, you might choose to randomly add or subtract a small random value to the y-velocity of the ball, to add a bit of unpredictability.

Pong, and bouncing ball physics in general, is fairly simple. There isn't much going on that you don't know about already.

##### Share on other sites
well what i did when i made mine was linear interpolation between the top and bottom of the paddle, so that when the ball hit the centre of the paddle it bounce back strait and when it hit either end it bounce of a 45 degrees, i can't remember how inplemented, but from what i can rmember it wasn'tto complex just basic linear algebra. search google for linear interpolation i'm sure there will be some decent articles and tuts. good luck

1. 1
2. 2
3. 3
Rutin
12
4. 4
5. 5

• 26
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633694
• Total Posts
3013381
×