User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Game Development section within the Software Development category of DaniWeb, a massive community of 429,763 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,893 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Game Development advertiser: Programming Forums

Breakout Ball bouncing physics

Join Date: Jul 2006
Location: Deptford, London
Posts: 964
Reputation: MattEvans has a spectacular aura about MattEvans has a spectacular aura about 
Rep Power: 5
Solved Threads: 48
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Posting Shark

Re: Breakout Ball bouncing physics

  #4  
May 5th, 2008
The position of the paddle when the ball hits it is wholely irrelevant - the paddle is the same all over, flat, and moves in a constrained direction ( in its own plane ), so any moving point on the paddle is 'identical' to any other point in terms of any calculation you perform. The only areas of the paddle that ARE different are the corners, do you model that accurately?

The quick trick you describe ( inverting one of the components of the moving object's velocity on a bounce with a plane ) works irrespective of the initial angle that the ball is travelling at; if you start the ball moving at any angle other than 45 deg, then bounce angles will be a little more 'varied', because only 45 deg will invert as itself. Any other angle will have slightly more possible results.

But.. I get what you're saying. Given any initial starting angle, and assuming that the player is 'perfect', and assuming that you don't handle corners of the paddle in any special way; the movement of the ball will always be exactly the same; the game is deterministic with a perfect player.

I am not sure if that's how breakout always is.. Alot of basic collision detection code assumes that a collision happens instantanously, and I believe ( although I may be completely wrong on this! ) that if a perfect sphere bounces off a perfect plane, that the velocity of the plane that is in the plane doesn't affect the bounce angle of the sphere. Like I say, I may be wrong

For a quick solution, instead of doing this with the ball velocity after a bounce:
velocity2[x] = velocity1[x];
velocity2[y] = velocity1[y] * -1;
try this:
velocity2[x] = velocity1[x] + ( paddle_velocity[x] * some_constant );
velocity2[y] = velocity1[y] * -1;
[[ some_constant should be between 0 = original behaviour and 1 = lots of sideways effect ]]

the effect here, is that if the paddle moves in the horizontal direction that the ball is moving, the ball will bounce 'flatter', if the paddle moves in the opposite horizontal direction, the ball bounces upwards more sharply. this is sorta like the paddle being rough, the collision being non-instanteanous, and 'pushing' the ball sideways slightly if the paddle moves fast enough.

bear in mind, that this will add energy to your system ( or remove it ) over time. normalize the post-collision velocity and multiply it by the length of the pre-collision velocity to prevent that.. [[ in a system that doesnt have a player adding forces, you'd normally conserve the energy by pushing the paddle backwards ( or starting it spinning ) after the bounce.. but.. that just wouldn't be breakout would it. ]]
Last edited by MattEvans : May 5th, 2008 at 11:41 pm.
If it only works in Internet Explorer; it doesn't work.
Reply With Quote  
All times are GMT -4. The time now is 3:32 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC