Matter-js: Maintaining stability for arbitrary body+constraint structures.

Created on 13 Feb 2018  路  4Comments  路  Source: liabru/matter-js

Does anyone have recommendations on how to create stable complex structures using a nodes and edges framework? I'm working on something that's along the lines of "World of Goo" or "Fantastic Contraption". I tried using rectangular bodies for edges pinned to circular bodies for nodes by using zero-length constraints, but once a structure gets reasonably complex I'm seeing erratically unstable behavior like this:

unstable

Any thoughts or advice would be appreciated!

question

All 4 comments

Try these out:

  • increase engine constraint iterations e.g. engine.constraintIterations = 10
  • relax the pin constraint stiffness e.g. constraint.stiffness = 0.01
  • in addition to the rectangle bodies also add constraints between the same points
  • generally probably need to add more invisible cross braces

Thanks!

I already tried reducing the stiffness, but that didn't help too much and had the side effect of making the structure collapse into itself.

I tried increasing the iterations and that helped make it less likely to happen, so it gets me closer! I can make the structure more complex now, but it eventually breaks as I add more to it.

I'll try adding constraints between nodes and see how that does. I've noticed that the instability seems to occur first on a node with 4 or more constraints, especially when there's a decent amount of stress on one or more of the constraints. Nodes with 3 or fewer are generally fine until the rest of the structure goes berserk.

unstable-2

Thanks for your help @liabru!
Using a combination of your recommendations, I was able to get it to function correctly with much more consistency:

  1. I set the iterations back to the default. I may bump it up if things start breaking again, but it's working well with the following changes.
  2. I set constraints between node bodies that match the length of the edge bodies. The stiffness on these constraints is set to 1 to maintain structural integrity.
  3. I retained the constraints between the node bodies and the ends of the edge bodies, but reduced their stiffness to 0.1: this removed the erratic instability, but keeps the edge bodies nearly in place for collision effects.

Great, this type of thing is usually takes a bit of trickery in physics engines to get right. You might also want to try varying the mass of each body (less mass as it goes up?), increasing air friction and even enabling sleeping.

Keep me posted, will be cool to see where you take this!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ShadewEnder picture ShadewEnder  路  3Comments

djipco picture djipco  路  4Comments

jack-guy picture jack-guy  路  3Comments

maximilianberndt picture maximilianberndt  路  4Comments

car1ot picture car1ot  路  3Comments