Hey guys!
I have a question about collision response.
In my program I check if some circles collide, and if they do, the collision is being resolved and the new velocities are being set.
That works fine if the circles have the same radii, but when the radii are different, the circles stick together sometimes.
a video showing the problem. ( I recommend you to watch it in fullscreen mode. The password is 'sfml')
Here's my resolve circle to circle collusion function:
void resCtcCollision(elasticCircle &circleA, elasticCircle &circleB) //Resolve Circle to Circle Collision
{
sf::Vector2<long double> v1(circleA.getVel());
sf::Vector2<long double> v2(circleB.getVel());
sf::Vector2<long double> ap(circleA.getPosition());
sf::Vector2<long double> bp(circleB.getPosition());
sf::Vector2<long double> n = ap - bp;
n = Normalize(n);
long double a1 = dotProduct(v1, n);
long double a2 = dotProduct(v2, n);
long double optimizedP = (2.0 * (a1 - a2)) / (circleA.getMass() + circleB.getMass());
v1 = v1 - optimizedP * circleB.getMass() * n;
v2 = v2 + optimizedP * circleA.getMass() * n;
circleA.setVel(v1);
circleB.setVel(v2);
}
My timestep is correct.
Has anyone an Idea what I've could done wrong?