Advertisement

2D collision problem

Started by August 23, 1999 12:18 AM
4 comments, last by GameDev.net 25 years, 3 months ago
How exactly are you determining when the polygons collide? In my mind it seems that if you know they collide then you should automatically know where they collide... perhaps I do things differently.

-fel

~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
Ya, im using line - line interesection tests. I need to find the exact point of contact where one vertex of one polygon contacts an edge of the other polygon. The polygons dont move fast enough to warp through each other so i dont usually do point in poly tests, except for bullets.

-ddn

Advertisement
I've thought about this a bit over the last few weeks, but been too busy to implement or test anything, so I don't know if any of it works... It sounds like what you're doing is much like what I'd like to do (Mine is an optional extra atm though, so is sitting on the sidelines *sigh*), might like to have a little chat with you and compare

The binary interpolation method should work, but there may be a problem with accuracy with integer division (an object moves 15 pixels in 1 frame, hence 7 pixels in 1/2 a frame, 3 pixels in 1/4... May not be a problem tho)

You could also extend your collision detection routine to, instead of simply saying 'yes' or 'no', to specify exactly which polygon edges participated in the collision. If your polys move within certain speeds, this info should be enough to interpolate an approximate collision coordinate.

Another method I just thought of (so have no idea at all about viability) is to extend the poly collision algorithm to return the 1/1000th of a frame segment in which the polys collided... that'd cascade down to the line intersection routine, to handle moving vectors. I'll work this one out on paper and let you know.

Regards,

White Fire

Addit:
I never did find a satisfactory way to handle three-way collisions... the collision time becomes too critical, and do you dynamically recompute the velocity and redetect for purther collisions? Ideal, certainly, but how computationally expensive to be accurate?

[This message has been edited by White Fire (edited August 19, 1999).]

Thanks for all your suggestions. Well it seems like the best path for me, is not to worry about it. I have an adequate collision detection routine, and since i'm not doing a realsitic physics simulation i dont need the true time and point of collision. cya!

But from thinking about it the binary interperlation is actually the best way, but i would cull down the set of lines to be tested. Also since i wanted to know when 1 vertex hits another line, i would use point to line inclusion tests (when a point is inside of a poly vs outside) instead of line line intersection tests. From a sample of my test collision cases it about 2 lines and 2 points, so its not too expensive. You might want to try that White Fire.

-ddn

Hi, I'm making a top down game, and i'm having problems with the collision detection. It's a top down game so im only concerned with 2d collision detection. All the entities are bounded by collision polygons. Now, i can find when the polygons collide, but for accurate physics i need to know the exact points of collision. I've got some ideas, using a binary search in the time inbetween the collision and last frame, to find the collision point but that would be very expensive for the number of collisions i'm expecting to occure at one time. Any ideas?

-ddn

Doesn't it always seem the way though? The easiest way to fix it is to work out how you can do without it? (I'm lucky and can make a choice between destroying one of the objects or ignoring it totally) Would have been nice to work it out, tho. (sigh)

Not sure about that point-in-poly testing tho... that's basically just a sequence of line segment tests, and I've optimised all heck out of my line testing code (Worst case when lines aren't parallel: 9 additions, 10 multiplications and 2 integer divisions, plus the requisite dozen-odd comparisons and logical ands

Might be interesting to shunt the binary interpolation side of things back into the line intersection code tho, save untold redundant line checks...

Anyway, luck with your project,

White Fire

This topic is closed to new replies.

Advertisement