简体   繁体   中英

Box2d bodies unstable and does not come to rest

I was trying to experiment with box2d as a PoC for a game project, well i managed to create the world and bodies and default DebugDraw in place. Have been playing with restitution, density and friction but could not get the desired behavior and the bodies are unstable and keeps on flickering/bouncing that too very fast.


SEE the running code here: http://jsbin.com/qoceranu/1/edit


I have tried following things:

  • Setting the restitution values to 0.0 but that does not give the right behavior.
  • Tried various scaling factors. physics.SCALE which is number of pixels per meter in current implementation. It defaults to canvasHeight / physics.heightOfWorldInMeter .
  • Tried various animation step timings.
  • Tried using requestAnimFrame

As i am new to it, hence i believe i could be doing something fundamentally wrong. What do you think is the problem? Bodies never come to rest, neither its the natural behavior.

Thanks in advance.

The step length is waaay too long. Try changing this line:

physics.renderingEngine.init(~~(1000 / 60), 10, 10);

to:

physics.renderingEngine.init( 1 / 60 , 10, 10);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM