Saturday, November 27, 2010

Simultaneous collisions

Until now, I'd been (mistakenly) assuming that only one collision would occur between any number of objects per frame. Basically, I had one "collision" variable that kept track of which two objects were colliding and the point of impact (which determines the torque exerted on the object about its center of gravity).

Unfortunately, I failed to consider that an object at rest on the ground is in a constant state of collision (with the ground, obviously). What this means is that if an object has come to rest on the ground and another collision occurs, it goes undetected. For instance, another object coming into contact with the ground, instead of bouncing off, flies right through it and disappears into negative infinity. Wonderful! But not really.

So I'm implementing a system where new collisions are added and removed dynamically as they occur, but it's proving problematic for my feeble tired mind at the moment. There's currently a bug that causes an infinite loop (I think) and I can't quite pin it down just yet. Hopefully I'll be able to soon.

Otherwise it's coming along just okee dokee. I'm adding angular acceleration from impacts that cause the objects to rotate once collided, as well as conservation of momentum. The direction of angular acceleration isn't quite accurate, however, as they tend to spin in random directions unrelated to the point of impact. In other words, it's not exactly a good physical simulation, but it will suffice for now.

No comments:

Post a Comment