Hi guys,
I have managed to cobble together a simple phyiscs simulation with random line geometry, and as many balls as I wish to create, all of which posses mass, resitituion and friction properties,
Collision and all of the physical properties seem to work fine, but I can't get the balls to settle, once they are close to rest, they keep jittering and bouncing slightly, and it's really unappealing. I tried implementing a threshold, but it did not solve my problem. Here's a section of the main loop.
for(int i=0;i<balls.size();i++)
balls[i]->update((float)(SDL_GetTicks()-time));
time=SDL_GetTicks();
for(int i=0;i<balls.size();i++){//balls vs balls
for(int j=i+1;j<balls.size();j++){
V2 coll_normal;
if(balls[i]->checkBallColl(*balls[j],coll_normal)){
balls[i]->handleBallColl(*balls[j],coll_normal);
coll_normal.x*=-1;
coll_normal.y*=-1;
balls[j]->handleBallColl(*balls[i],coll_normal);
}
}
}
for(int i=0;i<lines.size();i++){//lines vs balls
for(int j=0;j<balls.size();j++){
V2 point(0,0);
if(balls[j]->checkLineColl(*lines[i],point)){
balls[j]->bounce(point);
}
}
}
I was wondering if anyone has a good perspective on settling the balls to a resting state.
Thanks,
Mike