Skip to main content
GameDev.net gamedev.net
🔒 Locked

Arkanoid collision detection

Started by wings_wings Feb 14, 2003 at 3:46 AM 5 replies 7k views
Original Post
wings_wings
wings_wings
Hello, i am trying to make a 2D arkanoid clone. Now i am facing the biggest problem. How do detect the ball-block collision and knowing which "side" of the block the ball collided on ? I first tried BOX-BOX collision. when the ball hit the corners it gets wierd results. PS:I am using interger calcuation because i am dev on J2ME platform. TIA.
S1CA
S1CA
Just make the bounding box for the ball smaller than the radius of the ball so that the box fits *inside* the ball (i.e. none of the corners of the box pop out of the circle/sphere)!
The reason you do that is so that the "space" in the curved part of the ball doesn''t count as a collision.

On many of the original arcade games from back then, things were much simpler than people assume nowadays - all integer, and none of it "proper" collision detection - just a knowledge that what the player is "seeing" is a frame or so behind what your collision code is "seeing" ... Though this might not be so applicable with J2ME if you aren''t double buffering.

Last time I knocked together an Arkanoid/Breakout clone (many many moons ago), I used box<->box and it was fine back then.


If you wanted to go over the top you know the direction the ball is travelling in (i.e. you can make a vector for it in fixed point or scaled integer) so you can predict where it''ll be in a few frames time, so instead of performing the collision on the current (and visible if you single buffer) position, you perform in on NEXT frames position.

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
wings_wings
wings_wings
Hi, thanks for your reply.

The real problem i need to solve is which EDGE on the dest-rectangle that the source rectangle hit on. so i can relfect source-rect''s moving direction.

thanks
lukeyes
lukeyes
I''m working on an arkanoid clone right now, and what I did is move the ball back to where it was last, and then see if ball is in the same vertical area as the paddle. If it is, then you have a side collision, and if it''s not, you have a top-down collision.

seems to be working, now all I have to do is check collisions against diagonals.
evillive2
evillive2
It depends on how accurate you want to be. Using the boxes should be fine for rough detection then use the position of the corner(s) inside the block to figure out which side you hit.

ball has corners
1|2
---
4|3

+-------------+
| 1|2
| 4|3
+-------------+

if 1 and 4 are inside the block, the only side it could have hit is the right side.

+-------------+
| |
| 1|2
+------------4+3

forgive my ascii but if corner 1 is the only corner inside then depending on which of the balls corner 1 x or y is in deeper you can figure out which side you hit first.

hope that made sense.
Evillive2
FerretallicA
FerretallicA
Heh, this brings back memories... I did a dodgy Arkanoid clone for my major Software Design assignment back at Girra High. I didn''t bother detecting which edge of a brick the ball hit. I used the (x,y) co-ordinate of the ball to get the 9 bricks it could possibly be touching (3 to left, three to right, one above, one below, one in the middle closest to the ball''s position). For the 6 on the sides, if the ball was touching it I set the ball''s x velocity to the inverse (ie Ball.XSpeed = 0 - Ball.XSpeed). For the 6 on the top and bottom I inverted the y velocity if they were touching. Simplistic maybe, but-

* It was fast
* It looked good enough
* It worked

You''d still need to take into account when the ball hits the corners of a brick instead of the sides, but I didn''t and it still looked good enough.

DISCLAIMER- THe use of terms like speed and velocity may not be 100% correct with regard to formal physics. I don''t care.
Intelligence is only a state of mind.
FerretallicA
FerretallicA
Heh, this brings back memories... I did a dodgy Arkanoid clone for my major Software Design assignment back at Girra High. I didn''t bother detecting which edge of a brick the ball hit. I used the (x,y) co-ordinate of the ball to get the 9 bricks it could possibly be touching (3 to left, three to right, one above, one below, one in the middle closest to the ball''s position). For the 6 on the sides, if the ball was touching it I set the ball''s x velocity to the inverse (ie Ball.XSpeed = 0 - Ball.XSpeed). For the 6 on the top and bottom I inverted the y velocity if they were touching. Simplistic maybe, but-

* It was fast
* It looked good enough
* It worked

You''d still need to take into account when the ball hits the corners of a brick instead of the sides, but I didn''t and it still looked good enough.

DISCLAIMER- THe use of terms like speed and velocity may not be 100% correct with regard to formal physics. I don''t care.
Intelligence is only a state of mind.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.