Jump to content

boxes stack unstable


Recommended Posts

Hello guys

In my game I need dynamic bodies being stacked on each other. The problem is that such construction is totally unstable. Everything is shaking and sliding constantly.

Here is simplified example:
after 5-6 seconds tower starting to swing, then some boxes starting to slide.

Adding friction makes everything even worse.

Any suggestions?

Link to comment
Share on other sites

Thats strange,. If you set the damping of each box to 1 it will be stable, but the collision does not look realistic anymore. 


Some suggestions, which might/might not be applicable to you:

-trigger the damping back to 0 when your player/collision object is approaching the stack, since after the stack of boxes collapse you don't really care about stability.
-set view.body.static=true when creating the boxes.  When your player/collision object approaches the stack, set it to false. Same reason as above.
-there is a demo for P2.js that has a similar setup. Maybe you can find some settings you can adjust via these examples?
- Downgrade to arcade physics?

Im curious to know what is going on internally. Maybe someone has an idea?

EDIT: here is a similar post about this. The author of P2 also mentions it is difficult to solve:


Link to comment
Share on other sites

Thank you for your reply!

Best way to fix this problem is to increase simulation iterations count. Default engine value is 10. Setting it to 100 makes physics perform really smooth, but it's totally not acceptable for mobile platforms (which is one of my targets).
So I have slightly increaed it (to 18) and enabled sleep mode for bodies.
Sadly sleep mode also has problems: destroying bottom box not wakes up higher one, which were on destroyed box. So right now I'm waking up all boxes manually on removing one.
Its all feels like hacks. I have experience in Box2D and Nape on other platforms, and there is nothing like that there, while using 8 simulation iterations.

Current situation is acceptable for mvp and checking game concept, but later I'm planning to try Arcade/Matter.js/Box2D. General impression about p2 is terrible. Maybe I dont know how to use it, but other engines on other platfroms were performing much better.

Code for increasing iterations count:
game.physics.p2.world.solver.iterations = 18;

I will update this thread, when I will get new results.

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...