Collision Response

I have been building a collision response engine in Java and sometimes it does some odd things. I would appreciate it if any of you could clue me in on to what exactly is going on. The link to the engine is

merrill541 Wrote:I have been building a collision response engine in Java and sometimes it does some odd things. I would appreciate it if any of you could clue me in on to what exactly is going on. The link to the engine is

Well, I've noticed that the balls get stuck together quite often. They don't always stay stuck for long, but it looks like you aren't solving interpenetration before applying rebound force. It seems as though you are simply calculating the rebound needed, and then continuing without separating the balls beforehand. I would look into solving interpenetration.

Other than that, the demo looks great! I spent a good 20 minutes adding balls and trying to keep them from clumping. Nice work!

Mac users swear by their computers, PC users swear at their computers. ~Unknown

I do have another version of the physics engine, the collision response is not as accurate but it never lets objects go together and it never applies huge amounts of force seemingly coming from nowhere. The link is

merrill541 Wrote:I do have another version of the physics engine, the collision response is not as accurate but it never lets objects go together and it never applies huge amounts of force seemingly coming from nowhere. The link is

What is your method for this new one? It doesn't handle overlap well: it sticks all the balls that are created on top of one another in the upper left hand corner. Also, your coefficient of restitution (how much the balls stick together) seems to change for some balls. The detection seems to be much snappier on this one and the balls no longer clump together, so you're getting there! Keep up the good work.

Mac users swear by their computers, PC users swear at their computers. ~Unknown

Are you applying forces or impulses? An impulse is an instantaneous change in the velocity of an object, which is what you want for collision response. Your objects seem "soft," like it takes some time for the collision response to take affect (i.e. not instantaneous).

Also, it seems like you are not doing any sort of angular simulation. For true realism, it is necessary that you take angular effects into account in order to produce phenomena such as rolling, etc.

When you say angular simulation, do you mean rotation? If you do, I do plan on adding rotation to the objects but right now I have just been working on the x and y distance forces.

In answer to your first question, the way the forces work on these objects is that each object stores it's own force and every time I recalibrate the forces it changes it's own position. So when the objects collide I first change the position back to where it was before the forces were added to the position and then add my collision response forces.

This version is very simple and handles the collisions better because of that. All it does is when two objects collide it sets the objects force to 0 and then adds the force of the object it hit too itself. For example when one object is not moving and is hit by a moving object you will notice that the object that hit stops moving completely while in the other version it sometimes would bounce off at an angle or zoom off at incredible speeds.

I'm not really sure why it wouldn't handle overlap, unless when it changes the position of one it detects that it is overlapping another, which I haven't really made a solution for at this point.

I'm not really clear on what you mean by how much the balls stick together, but the only thing that varies between the balls is how much of their force is sent back to them when they hit a wall (it is generated by a random number generator). Some of the balls will bounce only once or twice when you turn gravity on and some will seem to never stop bouncing.