#### Archived

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

# Collision detection for breakout

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

## Recommended Posts

Hello all, Firstly I''m sorry if this is the wrong forum to post this question in but I''m new here. I''ve written a breakout clone in Borland Turbo Pascal 7 and it''s pretty much complete except that my collision detection algorithm really sucks for ball / brick collisions. The ball advances between 3 and 6 pixels horizontally each frame (depending on skill level) and I think this is causing problems with detecting collisions. The problem I''m having is that because I need to alter the direction of the ball I have to know not only if the ball has hit the brick but aslo which side of the brick it has hit. Does anybody have any suggestions? Thanks, Steve --------------------- Light of my life Fire of my loins. My sin, my soul LOLITA ---------------------

##### Share on other sites

I''m not sure what to tell you at this point.

First of all, with a maximum vector of 6 pixels, there
is a chance of a six pixel overlap, or the ball being six pixels from the brick upon collision.

With a six pixel difference, that is quite large. But at the speed the ball would be traveling at that rate, the distance differential between the ball and brick would be kind of blurred.

For collision purposes, you might consider putting feelers out from the center of the ball. Depending which feeler hit the brick would give you indication of what side the brick you hit. From this you could derive you new ball vectors.

I would opt for a collision before the ball actually hit the brick. I say this because if you collidied with a pixel overlap, the new vectors might not clear the collision.

So what you would do is check ahead of the actual ball movement by adding the future ball vectors to temp variables. Then you could calculate a possible collision.

Some pseudo code:

temp_position_x = ball_left_pixel_x + ball_vector_x;
temp_position_y = ball_left_pixel_y + ball_vector_y;

If ( left_pixel_collide( temp_position_x, temp_position_y ) == TRUE )

Then ball_vector_x = - ball_vector_x,

ball_left_pixel_x = ball_left_pixel_x + ball_vector_x;
ball_right_pixel_y = ball_right_pixel_y + ball_vector_y;

You could do this for each side of the ball, and of course updating the balls position as well. You can experiment by setting the feelers different distances form the ball to get the effect you want.

Guy

##### Share on other sites

I''ll try that implementation out tomorrow. I''m sort of feeling my way with game programming from whatever I can find on the web and what little assembly language I know.

Cheers,

Steve

---------------------
Light of my life
Fire of my loins.
My sin, my soul
LOLITA
---------------------

##### Share on other sites
I tried the ''feelers'' idea and it''s a big improvement over what I had! Many thanks!

Steve

---------------------
Light of my life
Fire of my loins.
My sin, my soul
LOLITA
---------------------

1. 1
2. 2
3. 3
Rutin
13
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633700
• Total Posts
3013418
×