## Yet Another Collision Detection Question

t3knomanser
Unregistered

Post: #1
I've googled, and read through here, but I'm not seeing anything that maps to my particular collision detection problem.

I'm doing a motion-sensor based application on a MacBookPro (and later for PowerBooks, iBooks, et al), based on the old tabletop Labyrinth mazes. You have to tilt the laptop to control the ball. All of that works fine.

I've written some logic that tests to see if the ball crosses into a rectangle that represents a wall, that works fine too. The problem is, I need to figure out which direction the ball was crossing, and stop the ball so it's like it hit a real wall. The way I'm doing this right now is to:

Check the last location of the ball and the current location of the ball against the bounds of the rectangle- based on where it crosses, move the ball out to coordinates that place it against the wall.

That works, so long as the ball hits squarely on one of the sides of the square. When it hits a CORNER, a skilled and careful player can make the ball pass through the wall.

So, I can detect collisions using a simple bounds test, and then, based on the previous and current locations of the ball, I do an a posteriori test to see where the ball broke through, and then reposition the ball against the outermost edge of the box in that direction.

The problem with my current methodology is that the ball can pass through the corners of the box. How do I resolve this?
Member
Posts: 304
Joined: 2002.04
Post: #2
You need to also have a circle/point collision function which you apply to the corners in addition to testing edges. If you make a circle/circle collision function then you can add circles as well as rectangles to your maze (they can also become "holes" that you have to maneuver around if you want!) I mention this because circle/circle can be used as circle/point if once circle has a radius 0.

Check out:
http://www.geometrictools.com/Intersection.html

hth,
Codemattic