Help!Bounding collisions

Started by
2 comments, last by Guthur 15 years, 4 months ago
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?
Advertisement
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    |
Innovation not reiterationIf at any point I look as if I know what I'm doing don't worry it was probably an accident.
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?....
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
Innovation not reiterationIf at any point I look as if I know what I'm doing don't worry it was probably an accident.

This topic is closed to new replies.

Advertisement