Collision Detection Algorithm

Started by
23 comments, last by EvilProgrammer 20 years, 2 months ago
I''ve written triangle-triangle collision that does not work on intersections; it finds the exact distance between two triangles along the movement direction and handles the collision correctly (including "sliding" collision). I''m working on writing an article/tutorial on it but for now you can try to make sense of the source code posted here. The algorithm for calculating the bounced vector (the new movement direction after you hit something) isn''t totally perfect, but otherwise it should work without a problem.

~CGameProgrammer( );

Screenshots of your games or desktop captures -- Post screenshots of your projects. There''s already 134 screenshot posts.
~CGameProgrammer( );Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.
Advertisement
Im a little curious about some of the ideas presented here. Mainly the one where you (1) find all collisions, storing them in a list sorted by time of collision (2) do physics, apply forces on the first collision in the list (3) move all objects to the point in time where the first collision occurred (4) goto 2 until the list is exhausted.

Would this scheme work when a collision is a constant one? Like when a ball is resting on top a plane, and gravity is constantly pulling the ball directly down on the plane. It seems like in step 2 when you apply forces, nothing would happen with this collision and it would still collide instantly. Wouldn''t that mean it would still be the first in the list, and the loop would just stay there forever?

- Jeremiah

inlovewithGod.com
Right sliding is not required, I can rely on impulse only in the particular game I have in mind and the test I already made (many balls on a planar surface (2D)). However, I would consider constrainted physics differently. Within certain conditions, I would add temporary constraints. For instance a planar constraint for sliding. I already explained the scheme in details in another thread at GD. But it''s true that I still have not tested it in real life. It may be full of subtelties to handle. Also something most probably required is cinetical energy must decrease, this avoids decor traversal instead of movement decrease then rest (you infinite loop remark).
"Coding math tricks in asm is more fun than Java"
Im sorry, but I dont understand what you''re trying to say. Could you elaborate on your method and how it fixes the inifinite "resting object" loop? Thanks.

- Jeremiah

inlovewithGod.com
Well, one thing you could do is only apply the force of gravity once, at the beginning of the frame. Then you only get one collision, handle it, and after that you''re fine.

Another approach is to have a flag for each object that tells if the object is at rest. If an object is at rest, it is sitting on something and the force of gravity is assumed to be instantaneously counteracted by that something. So when the object''s at rest, you don''t apply gravity to it and wait until someother object applies a force and gets it moving again.

This topic is closed to new replies.

Advertisement