Hi guys,
I'm trying to get stable box stacking with my physics engine. I use an accumulated impulse model but I dont pre-apply last accumulated impulse at the beginning of each timestep, basically I don't have a preStep function as in box2d lite. Actually, I tried to implement it but it made the simulation totally unstable. I create persistent contact manifolds by checking contact proximity at each step, I use something like;
if (contact.position.distanceToSquared(contacts[i].position) <= 0.004) {
// Use previous contact impulses
}
My allowed penetration is 0.01 and bias is 0.1, iteration 10.
At each iteration I calculate impulses like this;
// Normal Impulse
deltaNormalImpulse = c.massNormal * (-vn + c.bias)
oldImpulse = c.normalImpulse;
c.normalImpulse = Math.max(oldImpulse + deltaNormalImpulse, 0.0);
deltaNormalImpulse = c.normalImpulse - oldImpulse;
// I use the same approach for calculating the tangent and binormal impulses
deltaTangentImpulse = c.massTangent * (-vt);
maxTangentImpulse = 0.6 * c.normalImpulse;
oldTangentImpulse = c.tangentImpulse;
c.tangentImpulse = clamp(oldTangentImpulse + deltaTangentImpulse, -maxTangentImpulse, +maxTangentImpulse);
deltaTangentImpulse = c.tangentImpulse - oldTangentImpulse;
deltaBinormalImpulse = c.massBinormal * (-vb);
maxBinormalImpulse = 0.6 * c.normalImpulse;
oldBinormalImpulse = c.binormalImpulse;
c.binormalImpulse = clamp(oldBinormalImpulse + deltaBinormalImpulse, -maxBinormalImpulse, +maxBinormalImpulse);
deltaBinormalImpulse = c.binormalImpulse - oldBinormalImpulse;
and here is the result;
https://vimeo.com/135466972 (Watch on vimeo for HD version)
Box stacking is not stable, they fall down in the long run. By the way, sleeping is not enabled in this demo, but I think it should be stable without sleeping, isn't it?
Waiting for your tips.
Thanks, Uza