Skip to main content
GameDev.net gamedev.net
🔒 Locked

best PONG bounce method

Started by Trashcann Jul 16, 2003 at 10:41 PM 3 replies 8k views
Original Post
Trashcann
Trashcann
Whats the best way to have a ball bounce off of a paddle like in pong? i have it bouncing off the top, but the corners are a bit tricky. any help is greatly appreciated.
ermokwww.truevision3d.com
Sneftel
Sneftel
Pong paddles have classically simulated ellipses in terms of rebound angle.. that is, as you move towards one edge, the ball starts being deflected more and more in that direction. If this were not the case, the game would probably be extremely boring, as the ball would maintain the same angle most of the time.
Roof Top Pew Wee
Roof Top Pew Wee
These exciting answers and more can be found in the all new "Book of Trigonometry."

Sorry, couldn't resist. Didn't mean to be a jerk about it, but the fact is that Pong traditionally is made by people looking to move further on in game programming, and if you are going to move on to bigger and better things, trig is at a minimum essential.

However, I'm going to assume you understand trig in my explanation. This may be a little overboard, but here goes. First you find the magnitude of the speed, which is just sqrt(xVelocity^2 + yVelocity^2).

Then you find the angle, which I believe is tan(yVelociyt/xVelocity). Of course, tan cycles every PI, or 180 degrees, but we're accounting for 360, so if xVelocity < 0, angle += PI. (I'm doing this all off the top of my head, so I hope I'm right).

Then you just adjust the angle. A reflection off of a horizontal surface is angle = PI - angle; Well, then you could go the whole rout of calculating the angle off of a circular surface, but that's not that much fun, so I'd say fake it. Just have a value that the angle changes by depending on the distance from the center of the paddle. Say your paddle is centered at Y. Then just do angle + (or - depending on xVelocity again) = constant*(ballY - paddleY);

If the ball is moving right, you want the angle to be less if the ball hits above the paddle. If the ball is moving left, you want the angle to be greater if the ball hits above the paddle. Try it out and you'll see what I mean, if you don't understand.

Then you reverse the angle and magnitude back into x and y velocity and you are good to go. This brings up more issues of timing and collision, but that's the beauty of easy games. They're not so easy


--Vic--

The future of 2D game development:
Flat Red Ball

[edited by - Roof Top Pew Wee on July 17, 2003 10:28:02 AM]
shurcool
shurcool
quote:
Original post by Sneftel
Pong paddles have classically simulated ellipses in terms of rebound angle.. that is, as you move towards one edge, the ball starts being deflected more and more in that direction. If this were not the case, the game would probably be extremely boring, as the ball would maintain the same angle most of the time.


not necessarily.

in some (if not most) pong versions, the angle of the rebound does not depend where the ball hits the paddle, but rather the speed that the paddle was moving at during the collision.

so if you move the paddle to the left while hitting the ball, then the ball will start moving [more] to the right.

this also makes more sense since most paddles are rectangles, not ellipses.

---
shurcool
wwdev
Trashcann
Trashcann
thanks for all the help- and dont worry im used to people being jerks to idiots like me
ermokwww.truevision3d.com

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.