flyover / box2d.ts

A TypeScript port of Box2D
https://flyover.github.io/box2d.ts/testbed
MIT License
405 stars 85 forks source link

position changes when collision occurs in a special environment. #55

Closed jcyuan closed 5 years ago

jcyuan commented 5 years ago

this does not exist on PC, our environment is a special one, if you use Chian shap to make a wall, and when a dynamic box hits it, the box will 'bounce' back once.

in my code: gravity: 9.8 box's linear velocity on horizontal is set to 4 road: whatever line shape or chain shap others are all default value

here is the test video: https://jc-space.com/test/v.mp4

as you can see, when the box hits the wall, it will be 'dragged' back (from x: 7.6 to 6.8) , and then move forward again (because I set linearvelocity in a loop), then back again, then loop again...

because this does not exist on PC and I'm not familiar with the principle of physics engine, so I have no idea at all what can cause this problem, float precision?? please help to analyze, thanks so much! this is really critical for us!

@flyover @finscn

jcyuan commented 5 years ago

I found that this is caused by the loop times (subStep.positionIterations) exceeded from the limited 20 times in the SolveTOI method of the b2Island class which means contactSolver.SolveTOIPositionConstraints failed the test, what caused this?

jcyuan commented 5 years ago

forget about this, sorry, this is caused by the platform, not the lib, so close this.

finscn commented 5 years ago

@jcyuan How to fix (avoid) this issue in your environment that the special one ?

jcyuan commented 5 years ago

it was my mistake, this version of box2d runs just well on wechat mini game.