#### Archived

This topic is now archived and is closed to further replies.

# Ideas & suggestions for breakout clone physics

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

## Recommended Posts

I am just a beginner to game programming, so I am following some advice I''ve been given on the forum, and am now making a breakout clone. My problem is this: I''m not sure how to correctly determine which direction and speed the ball should be going after hitting something (brick, wall, paddle) I mean I have the general idea, and right now, I have implemented a N, S, E, W (NE, NW, SE, SW) system, where it will go S if it hit something while going N, etc. This is obviously not correct, but it was what I started with. Now, I want to do something more accurate and complex. Any suggestions on how to get started with this? I know that I most likely need to keep track of what angle the ball hit an object with, so that I can send it out with a similar angle, but how do store this, or keep track of the information. Anyone with ideas, or who has actually done this, please respond. Thanks!

##### Share on other sites
it actually shouldn''t be too complicated if you are using rectangular bricks and whatnot (no rounded corners or angled walls or anything).
the trick is to store the ball''s position (x,y) and velocity (dX, dY). each frame when the ball moves, add dX to x, and dY to Y. to change the direction of the ball, change dX and dY as follows:
basically, if the ball bounces off a surface that goes up/down (ie the side of a brick, or the wall), you just reverse the horizontal velocity (dX = -dX). if it hits a left/right surface, reverse the vertical velocity.
the only problem with this (and it isn''t a problem with innacuracy, this over-simplified bouncing is no different than if you did all the trig calculations) is that the ball will always bounce in the same pattern; that is, if you have it start out at 45 degrees up and left, it will always be bouncing around at 45 degrees in some direction or another. you might want to "tweak" the angle of the ball when it hits the player''s paddle, based on how close to the center of the paddle it hits (so, when you just clip it with the edge, it goes more left/right than up/down, and if you hit it towards the center of the paddle it gives a truer bounce). this would add to gameplay and control and whatnot, rather than just following a ball when you always know how it will bounce.
if you want bricks to be at angles, or have weird shaped walls, or anything like that, you will have to learn some trig. because i am lazy i''m not going into that unless you actually say you want angled surfaces and stuff.

--- krez (krezisback@aol.com)

##### Share on other sites
I made a breakout clone a long time ago.. I did not use any real physics though.. it rocked!

##### Share on other sites
I made a breakout clone a long time ago.. I did not use any real physics though.. it rocked!

##### Share on other sites
Thanks for the reply kreg! I am just using normal, boring rectangles for bricks, so your idea will work great. I thought of something similar, but I just couldn''t convince myself that it was the way to go, after your reply and thinking about it more, I have to agree this is the best (and simplest) way to implement it.

Thanks again!

1. 1
2. 2
Rutin
21
3. 3
4. 4
frob
17
5. 5

• 9
• 12
• 9
• 33
• 13
• ### Forum Statistics

• Total Topics
632591
• Total Posts
3007250

×