Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / 2D breakout collision detection

Author
Message
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 19th Feb 2013 00:50 Edited at: 19th Feb 2013 00:51
Might seem a silly question coming from me, especially since I already made a Breakout clone for the old retro competition in DBC back in the day, but hear me out!
For some time I've been thinking of a more advanced method for collision detection in Breakout but so far every approach I try has been flawed.

Trial 1:
The play area is broken down into a static grid with vertical and horizontal lines having fixed spacing. I can quickly narrow down which bricks might be hit by eliminating which lines are crossed with the ball's velocity vector. (typically, only 1 or 2 lines will be checked unless the ball is moving insanely fast)
By doing a line-line intersection test I can detect the intersection point of the velocity vector against the vertical or horizontal line and easily determine the appropriate map coordinates and check to see if a brick exists at that location.

The problem, it's just a line but a ball has a radius. While the collision would work effectively, the ball could appear to cut corners as the only part of it involved in the collision would be the center of the ball. In other words, the ball's radius would appear meaningless to the end-user.


Trial 2:
I found a new algorithm for checking a swept-circle against a line. Basically it would be much like the first example only now the radius would mean something. But of course this had a flaw too. The first point of contact between the circle and the grid line could be just above a brick yet still actually colliding with the brick. The intersection point would check the map for the space above where the brick actually lies because that's where the line contact is made.





Trial 3:
As you can see, a moving circle creates a capsule shape. So I've been looking for ways to detect for collision between a capsule and a line segment, but I haven't come up with much. And I'm afraid it might fall into the same problem as the last example above.

At this point, I'm thinking perhaps a capsule and a box (AABB) check, but haven't quite figured out the best way of calculating that. So right now, I'm asking if anyone has a better idea for breakout collision while maintaining the sweeping aspect. Yes I could use Box2D, but that defeats the purpose of my project, which isn't to make breakout but to find a better method of collision detection. The game is just to be a demonstration of that technique.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 19th Feb 2013 17:51
It might be a good idea to check out how Box2D does their collision code:



In regard to the problem mentioned in Trial 2, can't you perform a distance check for the closest collision point?

Also, I found this : http://codeincomplete.com/posts/2011/6/12/collision_detection_in_breakout/

Another problem you'll encounter mentioned in the article above is when the ball hits multiple bricks, such as in a corner. Recommended is to recursively call the collision function again with the remaining distance the ball has to travel.

TheComet

http://blankflankstudios.tumblr.com/
"You're all wrong. You're all idiots." - Fluffy Rabbit
"Bottom line, people are retarded." - Fluffy Rabbit
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 19th Feb 2013 23:04
I already considered a recursive method to handle that issue, I just haven't bother with an implementation yet until I get the initial collision perfectly.


Here's my example for trial 2. If you play around with it a little bit you can see it doesn't always work.


"You're all wrong. You're all idiots." ~Fluffy Rabbit

Login to post a reply

Server time is: 2026-07-07 18:44:48
Your offset time is: 2026-07-07 18:44:48