   2D box collisions - multiple objects
  Picture the following example:You have three boxes in a row# # #You apply some kind of force on the one most to the left-># # #Then I want all of the three boxes to start moving with the applied force (or perhaps the force divided in three).At the moment I can solve a 1 on 1 problem i.e. if A is colliding with B with a force F, they divide the force F realisticly deppending on their velocity and mass. But whenever I try to spread it over more than two objects it deppends more on which of the items that are first to go through my collision algorithm. Whenever I try to google the problem I either find very complex solutions for collision detection with different kinds of pollygons and shapes, or I find the very simple 1 on 1 detection. This must be a problem that has been done and solved a hundread times before, so please if you got any good tips or links for a similar problem Id be happy if you shared it with me.//Doggolainen   
  It's similar to the stacking problem. It's not that straight forward actually, but working on pairs of objects at a time can give you reasonable results. You have three boxes A, B, C. A is pushed towards B. When A and B collide, The collision impulse will push B. Once B collides with C, the collision impulse will push C. B will then be pushed back, and collide back with A, which creates a resistance to the original force.So yeah, it depends on your object ordering, but in general, provided the physics time step is sufficient, the effect will be reasonably accurate. It's sort of how impulse-based physics engines work.   ;  Normally the physics engine would manage this automaticly as an emergent behaviour if you will, you apply the force to the left hand box, it's velocity is increased, the interaction with the middle box transfers momentum, which increases it's velocity which transfers momentum to the right hand box etc.(EDIT: blah oliii beat me :P)   ;Quote:Original post by oliiiIt's similar to the stacking problem. It's not that straight forward actually, but working on pairs of objects at a time can give you reasonable results. You have three boxes A, B, C. A is pushed towards B. When A and B collide, The collision impulse will push B. Once B collides with C, the collision impulse will push C. B will then be pushed back, and collide back with A, which creates a resistance to the original force.So yeah, it depends on your object ordering, but in general, provided the physics time step is sufficient, the effect will be reasonably accurate. It's sort of how impulse-based physics engines work.Thanks for a good answer!But heres a problem. Imagine if I have a list "List" of some sort. If I have all the boxes A, B, C in that list and want to check the collisions with all of them against eachother.Before collision:A#-> B# C#Result should be:A# B# C#->Lets say my collision algorithm works like this:for (i = 0; i < List.Count; i++){for(j = 0; j < List.Count; j++){  if(List collidesWith List[j]) //Checks collision all against allCalculateForce(List, List[j] //Divides the force correctly    }}This code would work if I know for sure that A is first in the list, B second and C last.But what if the scenario was different, like this:C#-> B# A#In this case when A will check its collisions, it wont detect any. Neither will B. And at the very last check C will notice a collision with B. Now I either have to iterate the entire list again (this could end-up in an infinitive loop btw). Or C will simply have to stop and wont be able to move that frame.I think I must be thinking the wrong way when Im letting all the boxes check against eachother. There must be something Im missing.   ;  B will detect a collision with A. The problem is C might not get a collision this frame, but will next frame. Again, it's the same problem with stacking objects. You have to start from the ground up to have a more stable stack. Usually, the code for collision detection of pairs of objects within a list is :for (i = 0; i < List.Count; i++){for(j = i+1; j < List.Count; j++)    {   if(List.collidesWith(List[j])) //Checks collision all against all  CalculateForce(List, List[j]); //Divides the force correctly    }}Then all pairs of objects are tested once. Again, the way to get around that problem is to run several simulations per frame, basically in-between when external forces are applied, and let the system converge to a stable state.The other solution is to sort collisions by time, that way the first collision will be processed first. There are ways, but it makes the code more obfuscated. If your objects are already in contact and resting, you can propagate forces or sort out priorities, but it can become quite complicated.If in doubt, use a 3rd party physics engine like Box2D, Chipmunk, of PhysX for 3D to do the dirty stuff for you.   