Suppose a basic game with several circles drawn to screen. The user can select and drag any ball and move it around the screen. Should the selected ball overlap with any other ball on screen, the other ball should displace so they are no longer touching.
The example I've seen use the following structure:
for (every ball pair):
if (collision = true){
- resolve collision
}
However, with this method, isn't there a risk that a displacement could cause an overlap in a pair already checked, and therefore the overlap printed to the screen?
Would it not be better to re-check every ball pair's collision, every time a ball is displaced, rather than every time-step?
Maybe something like:
for (every ball pair):
if (collision = true){
-resolve collision
for (every ball pair):
if (collision = true){
- resolve collision
}
}
EDIT:
Even the method I've listed above shouldn't always provide 100% accurate results. The only way I can think this could work is with some sort of recursive function which only stops when there are no more collisions. Does that seem right?