schteppe / p2.js

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

tunneling when colliding with polygon wall - no tunneling with wall made of several objects #136

Open valueerrorx opened 9 years ago

valueerrorx commented 9 years ago

i tried to make a simple testcase out of my current game to demonstrate the effect.. http://test.xapient.net/phaser/objectsvspolygons/

the wall is 32px thick in both cases ... the upper wall is a simlpe rectangular polygon and the wall at the bottom is made out of several tiles (it doesn't matter if i create them out of tiles or manually place them)

what counts is that the polygon wall allows tunneling almost every time while the other wall pushes the player back even if it's alreadi "IN" the wall it is beeing pushed back into the right direction.

to test: grab the big circle with the mouse and speeed up by using the spring forces and then throw the ball by releasing the mouse (or don't - it works while attached to the spring too)

regards

valueerrorx commented 9 years ago

this BUG is still a little bit of a show stopper for my game because tunneling occurs quite often.. and as i already said only with "thin" poligons.. thin shapes of normal objects are much better in handling this..

schteppe commented 9 years ago

Hi, The solution for this is probably CCD. And I've just gotten it to work with p2. Get the latest master branch, build and see demos/ccd.html.

valueerrorx commented 9 years ago

as far as i understand CCD would definitely be A possible solution.. and it's great to hear that we now have the possibility to fall back to this (probably very expensive) solution if it's necessary.. thank you very much for that. - but - the thing about this issue here is the difference between polygons and "ordinary" shapes of "ordinary" objects... the same wall made out of several object shapes is totally sufficient (for my case at least) while the polygon wall is behaving really bad..

isn't that strange? i'm curious.. why is this happening.. both walls have the same outer measurements - both walls rely on the same physics calculations (at least i thought they did)

thx again for your work.. p2 is really great :)

aaronransley commented 8 years ago

any progress on this? working with a team that's running into the same issue

schteppe commented 8 years ago

Try using a smaller time step, or activating CCD. Not sure how to solve it otherwise right now.

Using objects of approximately the same size would probably also help. And avoiding thin objects :)