2D collision - "jumping"

Started by
3 comments, last by leiavoia 18 years, 1 month ago
hi! i do have question about one thing. i'm trying to do 2D collision with sprites. i'm using the simplest way to do it - collision of 2 rectangles... it's works fine... the problem comes when i'm trying to put some dynamics into my program. let's say the object1 has speed 10. an object2 has width 2...object1 is going onto object2... in most cases the collision won't be detected because object1 simply "jumps over" object2... i have a few ideas how to solve it but i want to hear some advice from experienced people...so i'm not going to reinvent the bad wheel... thx
Advertisement
I use a system that predicts collisions instead of detecting them. Since I predict the time of collision mathematically, no misses can occur.

Other ways may involve using swept areas/volumes or multisampling (reducing the time step in artificial ways).
I'm no expert, but I have thought on the matter.

Here's an image that shows what I've thought about with regards to 2d collision detection algorithms.



Basically you keep testing until all collision lines and objects do not intersect with any other objects or collision lines.

It is important to step based on the time rather than the position of the start of intersection. Update position in response to updating time and keep time moving at a percent of the fastest object.
_______________________"You're using a screwdriver to nail some glue to a ming vase. " -ToohrVyk
Quote:Original post by M2tM
I'm no expert, but I have thought on the matter.

Here's an image that shows what I've thought about with regards to 2d collision detection algorithms.



Basically you keep testing until all collision lines and objects do not intersect with any other objects or collision lines.

It is important to step based on the time rather than the position of the start of intersection. Update position in response to updating time and keep time moving at a percent of the fastest object.
The above method might work with some tweaking (I'm not sure), but I just wanted to mention that for boxes and circles at least there are established algorithms for swept intersection that are robust and will handle all cases (within numerical limits). Box vs. box can be done using the separating axis theorem, circle vs. circle involves solving a quadratic, and box vs. circle is a little more complicated and can be approached a few different ways. Anyway, I just mention this because the OP said he didn't want to reinvent the wheel :)

Also, it sounds like the OP just needs a swept AABB vs. AABB test, which is fairly easy to code and is described in a gamasutra article linked in the 'collision detection' section of gdnet articles (I believe the author is Gomez).
Read this. It even has free code. Praise Oliii when you are done.

This topic is closed to new replies.

Advertisement