Ideas & suggestions for breakout clone physics

Started by
3 comments, last by saetrum 22 years, 5 months ago
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!
Advertisement
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)
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
I made a breakout clone a long time ago.. I did not use any real physics though.. it rocked!

The nightmare travels across the cosmos with his burning mane. The trail of ash that is produced.

?Have a nice day!?

I made a breakout clone a long time ago.. I did not use any real physics though.. it rocked!

The nightmare travels across the cosmos with his burning mane. The trail of ash that is produced.

?Have a nice day!?

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!

This topic is closed to new replies.

Advertisement