physics question
Im working on a simple pong game and need to know how to calculate the angle the ball will bounce off the paddle and how to determine the speed of the ball when it bounces off the paddle.
thanks!
Well, it all depends on how "realistic" you want it to be...
The most simplistic way of doing it is just to say that the angle of incidence equals the angle of reflection. This means that the speed of the ball in the direction parallel to the paddle will remain unchanged, and that the speed of the ball in the direction perpendicular to the paddle will remain the same in magnitude, but will reverse direction.
If you want to get fancy, you can "dampen" the balls motion by reducing its speed based on its "elasticity". For practical purposes you can just say that the balls speed in the direction perpendicular to the paddle is not only reversed after impact, but also reduced by some fraction.
Lastly, if you want to include rotational inertia, you can subtract from the balls speed in the direction parallel to the paddle after every impact add add the energy gained from that to the balls angular velocity.
The most simplistic way of doing it is just to say that the angle of incidence equals the angle of reflection. This means that the speed of the ball in the direction parallel to the paddle will remain unchanged, and that the speed of the ball in the direction perpendicular to the paddle will remain the same in magnitude, but will reverse direction.
If you want to get fancy, you can "dampen" the balls motion by reducing its speed based on its "elasticity". For practical purposes you can just say that the balls speed in the direction perpendicular to the paddle is not only reversed after impact, but also reduced by some fraction.
Lastly, if you want to include rotational inertia, you can subtract from the balls speed in the direction parallel to the paddle after every impact add add the energy gained from that to the balls angular velocity.
If a man is talking in the forest, and there is no woman there to hear him, is he still wrong?
When the ball bounces off a surface the trajectory inverts, but only if if there is no spin put on the ball. So if it goes in at a 20 degree angle it would come out at 160 (180 minus 20). Speed is a factor you figure in at your discretion. If you want to put spin on the ball just subtract or add a small amount of the exit angle of the ball. OK?
~Eric
~Eric
"there is beer coming from the chimney, code 3, I am proceeding on foot,i repeat bring pretzles."
The real world physics thing sounds nice. But, a pong type game doesn''t really use that. Instead, it depends on how fast the paddle was moving, and where on the paddle the ball actually touches. The speed of the paddle motion determines the end velocity (it keeps adding, the ball never slows down). The placement of the collision determines the angle that the ball bounces off. That was how I see the original was done.
Of course, in later times, the ball could slow down, if the paddle speed was great enough and the position of the collision was just right. This was the start of siulating the spin on the ball.
-MartinJ
Better living through creative confusion
Of course, in later times, the ball could slow down, if the paddle speed was great enough and the position of the collision was just right. This was the start of siulating the spin on the ball.
-MartinJ
Better living through creative confusion
You should create a ball object (or even just a struct) that keeps track of it's position (x,y), and it's movement. By far the easiest way to handle movement (speed, bounces, etc.) is to just have an integer to store it's horizontal speed (vx), and another to store it's vertical speed (vy). Positive vx means moving right, negative means left. Positive vy means moving down, negative means up. Eg. with a vx,vy of 3,-2 you know that for every step, the ball should be moved 3 to the right and 2 up (ie. x += vx; y += vy; ). You don't need an "angle" to keep track of, as an angle is nothing more than the relationship of x and y, relative to some origin. Here, the origin is the ball itself, and the "angle" is represented by vx and vy.
Now when you've detected that the ball hit your paddle or ceiling, just change the sign on vy. Bouncing off walls involves changing the sign on vx. That's it! Of course, you can put "English" on the ball by changing the vx and vy slightly based upon where on the paddle the collision occured, but that's simple too.
aig
Edited by - An Irritable Gent on May 9, 2000 3:40:15 PM
Now when you've detected that the ball hit your paddle or ceiling, just change the sign on vy. Bouncing off walls involves changing the sign on vx. That's it! Of course, you can put "English" on the ball by changing the vx and vy slightly based upon where on the paddle the collision occured, but that's simple too.
aig
Edited by - An Irritable Gent on May 9, 2000 3:40:15 PM
aig
Make up your own physics... that I think would be cool and more interesting. Make the annual battle pong championship game be on the planet Gossimer Omega V in the Quanton sector, where the ball is the racket and the pong is the ball. Weird, huh? Or perhaps the aliens there must sneeze the ball back and forth. Make sure to have plenty of Visine as bonuses.
"If you build it, it will crash."
Take the Gent''s advice as no one will notice (or even care) if your physics aren''t even 50% accurate Nick''s idea is kinda cool, though, but since this is only supposed to be a simple game, wait till you''re a little more experienced.
If you code it, they will come...
Commander M
http://commanderm.8m.com
cmndrm@commanderm.8m.com
If you code it, they will come...
Commander M
http://commanderm.8m.com
cmndrm@commanderm.8m.com
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement