http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

TheGrumpyProgrammer



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gameprogrammer] Re: Circle - Rectangle collison detection



On Wed, 2004-06-23 at 19:28, pallavnawani@sancharnet.in wrote:
> Hi,
> I am writing a (2D) arkanoid clone & I am having some problems with collison detection. The problem I am facing is that The ball has a tendency to pass by the corners of the bricks without colliding, although a slight overlap is quite clearly visible.
> 
> The method I am using is follows:
> I have two points (a) the point at the centre of the ball & (b)the point at which ball will be in future.
> 
> Now I calculate the equation of line between these two points & then check for intersection with four lines comprising a square.

Of course, this calculation doesn't include the size of the ball, so is
bound to be flawed!

I think the trick you need is to think of the box being a bit bigger. 
I'll try and draw you some pictures later, but see if you can picture
this:

You want to test for a collision between a ball and a box.  Imagine
rolling the ball all the way around the box, drawing a line at the
center of the ball each time.  The line the ball will draw will be a
bigger box - in other words, the center of the ball will never touch the
actual box, because the ball will get in the way.

So, instead of testing the intersection of your line with the 4 lines of
the actual box, pretend the box is bigger (Bigger in all 4 directions by
half the size of the ball) and test for intersection now.  You should
see the results you want.

There are a number of open source breakout style games, you could see
how it's done there - for instance in lbreakout at lgames.sf.net

Or http://xander.ncl.ac.uk/game/breakout/game.cc is for example a file with 
some very simple collision detection in it.

HTH!

> 
> Any suggestions/ alternative methods/ pointers to web resources will be appreciated.
> 
> Thanks in advance,
> Pallav Nawani
> 
> 
> 
> 
> ---------------------
> To unsubscribe go to http://gameprogrammer.com/mailinglist.html




---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html