Advertisement

Arkanoid/Breakout Collisions

Started by February 22, 2003 03:42 PM
0 comments, last by HUWUWA 22 years ago
Hi guys, I know some topics have been started about Arkanoid collisions but they don''t take many things into consideration so I thought I''d start a new one. I am having problems incorporating the ball (circle) radius into my collision tests. Maybe my entire methodology is wrong, please help. Here is what I am doing: I have no bricks or paddle yet, just four walls. All frames start with no collision. For each frame, calculate new ball position (center of circle), make line segment from old ball position to new ball position, test that line segment for intersection with walls (treated as line segments) then calculate the new ball position for the next frame if there is a collision. I have a few problems: 1) If the circle center is just before the wall there will be no collision even though the ball overlaps the wall. 2) if there is a collision with the line segments intersecting I don''t know how to find the point where the ball just touches the wall, it ends up half overlapping the wall before it bounces back. I am using the parametric representation of lines for these calculations. I am thinking that I have to do two tests, one if the ball totally overshoots the wall and only the line segments intersect and another if the ball is very close to the wall; am I right ? I want to get this perfect right down to the pixel. Please give me some guidance. Thanks guys.
If you have only horizontal or vertical walls it''s simple. We define the game field to be (x1, y1)-(x2, y2), where (x1, y1) is the top-left corner and (x2, y2) is the lower right corner. Then we have the ball, which is described so that
b.xpos = x position
b.ypos = y position
b.xvel = horizontal velocity
b.yvel = vertical velocity
b.radius = radius of the ball

then do the following tests
if(b.xpos - b.radius <= x1) b.xvel = -b.xvel;
if(b.xpos + b.radius >= x2) b.xvel = -b.xvel;
if(b.ypos - b.radius <= y1) b.yvel = -b.yvel;
if(b.ypos + b.radius >= y2) b.yvel = -b.yvel;

then move the ball a littlebit so that the ball doesn''t collide with the walls.

if you have the walls in different angles, it''s a completely different thing. another thing is that collision detection between a sphere and a rectangle needs a little bit of work.

Good luck.
-Richardo

---------------------------for(goodness_sake()){  do  {    something();  } while(you_can())}
---------------------------for(goodness_sake()){  do  {    something();  } while(you_can());}

This topic is closed to new replies.

Advertisement