Sign in to follow this  
Syed Atif Akhtar

Help!Bounding collisions

Recommended Posts

Ok so im working on a 2d pong game on XNA;to check for collisions,ive created bounding rectangles for every object...now the problem that im having is that sometimes....when the ball speed gets very high,the bounding rectangle of the ball crosses over the bounding rectangle of the pong without really intersecting it.... im doing something like this .....ballvector.X+=speed*gametime.elapsedmilliseconds and ballvector.y+=speed*elapsedmilliseconds.......now when X and Y attain a value that is larger than the height of the pong and the ball combined,they just cross over without the two rectangles actually intersecting each other...resulting in a ghost effect with the ball seeming to pass through the pong,how do i overcome this...without creating larger bounding rectangles?

Share this post


Link to post
Share on other sites
Its called tunnelling.

The objects collision is only tested after its passed through the other object in question. In simple form you need to test you collision over time.

EDIT: Diagram:

intial test (no collision still hasn't reached yet).

|
o |
|









next frame (still no colliding but wait thats not right :) ):

|
| o
|









It never collided within a frame bound test.

You need do something like this within each frame bound test ( each 'o' is a time segmented collision test, big O is the detected collision):


|
oooO|oooo
|







Share this post


Link to post
Share on other sites
thnx....so basically i need to run a loop AFTER the object has crossed over and check whther it shouldve collided or not by incrementing the speed of the object in small amounts when the ball was at its previous location?that does seem a bit logical........but then i will also have to run a loop and check whether the ball has crossed every other objects x or y location each time it moves.....wont i?....

Share this post


Link to post
Share on other sites
I'll not pretend like I am an expert, to be honest I would probably take the lazy route of using code/library that someone else put the nessescary time into. Its good to know it and one day I might put the effort in but...

Its called a sweep test this is one example:

Sweep test

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this