schteppe / p2.js

JavaScript 2D physics library
Other
2.64k stars 330 forks source link

Overlapping after fall (video) #275

Open ghost opened 7 years ago

ghost commented 7 years ago

I can provide code too if it will be necessary

How to decrease overlapping after fall down on static body? It looks very strange..

Circle body falls down and when it reachs ground (static box body) then it falls down a little.. more over static body, next step, it goes up to line of ground. Very visible.

VIDEO: https://webmshare.com/b8Wxy

this.world = new p2.World({ gravity:[0, 9.5] });
this.world.solver.iterations = 10; //more or less, not fixing problem
this.world.solver.tolerance = 0; //same here
World.prototype.update = function() { // called 60 times per sec
  this.world.step( 1/60 );
}
jtenner commented 7 years ago

High speed objects need CCD. Otherwise the object will be pushed into other objects and overlap.

ghost commented 7 years ago

but with CCD it still happens only a little less often.

Does CCD is created only for very small bodies aka bullets?

Does algorithm that works for any size of body exists?

schteppe commented 7 years ago

CCD can be enabled manually on bodies. Size does not matter. Not sure if it will help here.

I wrote a parameter tweaking guide for Cannon.js that should work for p2 as well. It should help minimizing the overlap. Read it here https://github.com/schteppe/cannon.js/wiki/Parameter-tweaking