Hi Professor Hwang,
This article is fantastic and has helped me a lot, but I am wondering if you might be able to help me out with a problem I have. I have made a program where I have multiple balls on the screen, each moving at a random velocity and in a random direction.
The problem I have is that when 2 balls collide, they will often stick to each other (especially when ed is < 1) and spin around orbiting each other. Each of the balls has a radius of 15, and so my collision detection is very simple, when the distance between two balls is <= 30 then there has been a collision. So, the problem is that when the distance is less than 30, (say 25), then they are overlaping by 5, when I next update the positions of the balls, if they havnt moved more than a distance of 5 away from each other since the last update, then they are still overlapping and the collision is still true. So, what I need to do is before the next update, I need to move the balls appart from each other a distance of 5 in the new direction after the impact. But I cant seem to figure out the maths to do it.
Also, I have implemented a bit of code to help handle when 3 or more balls collide at the same time, but it doesnt quite seem to work right. Do you have any tips for this?