Making stable buildings

Topics: Developer Forum, User Forum
Aug 18, 2009 at 11:09 PM
Edited Aug 18, 2009 at 11:10 PM

I'm having trouble making stable buildings.  Here are some screenshots of the problem in action:  I have some bodies and I've tied them together with pinjoints to try to keep things stable, but over time the building skews itself, the pins break and it all falls down. This process takes about 5 minutes or so.  This happens with SAT or Distance Grid, the screenshots were taken using distance grid.  I tried making the pins stronger but that just made the building movement more "jumpy" and pronounced.

I've fiddled about with various parameters, and currently am trying these settings, which I've taken from various posts I found regarding good settings for stacking.

PhysicsSimulator.BiasFactor = 0.05f;

PhysicsSimulator.Iterations = 10;

PhysicsSimulator.MaxContactsToDetect = 4;

PhysicsSimulator.MaxContactsToResolve = 2;

PhysicsSimulator.AllowedPenetration = 0.1f;

Then all my bodies are set like this:

mass = 1f;

frictionCoefficient = 1f;

restitutionCoefficient = 0.0f;

I was wondering, should I be structuring my building differently?  With diagonal struts or something?

Aug 18, 2009 at 11:53 PM

Might I ask why you are using pin joints? From looking at your screenshots, it sounds like a situation more suited for revolute joints. Note that the joints don't need to be within the geometries of the bodies. Maybe that's not the solution though... have you tried using the Inactivity Controller? Once the building comes to rest, it's guaranteed not to move for as long as nothing disturbs it.

Aug 19, 2009 at 7:46 AM

Or weld joints, maybe

Aug 19, 2009 at 8:42 AM

I think weld joints would be good.

I use 2 pin joints when i want really stable buildings.

Aug 20, 2009 at 6:00 PM

@Cowdozer, I was using pin joints only because I didn't know any better ;)

I've done lots of testing now and found some interesting results.  I tried welds and pins and revolutes, and initially it seemed like the tighter I tried to hold the building together the more violently it would tear itself down.  It was like there was some feedback loop and the building parts would jitter and jump more and more till whatever joint was there would break.

I think I found the problem though.

I had forgotten to attach the base of my building to the world, and I think there was some residual motion from where I created the building to where it settled a few seconds after creation.  So everything in the building drops a few pixels after creation whilst it settles, and that residual motion I think was my problem.  I added fixed revolute joints to the lowest vertical pillars to attach them to the world.  That way they dont move after the building is created and I now seem to have lost whatever residual motion there was and the building is stable.  Plus I only needed to fix these lowest pillars, the upper storeys are all ok as they are without any joints.  At least so far!

Thanks for the pointers folks.

Aug 20, 2009 at 9:48 PM

Do your buildings need to be able to move, shift, fall down, etc. sometime in the game?  If not, simply mark the objects in the building as Static.

Aug 20, 2009 at 10:39 PM

Good to hear you found a solution. The jittering you mentioned comes from the huge forces applied from trying to force the geometries together. The jittering is caused from the iterative algorithms in the engines and can be reduced by increasing the iterations. The stability of the engine can also be increased by increasing the iterations (try with a high number and decrease - Example: Try with 100, just to see if it helps).

Aug 22, 2009 at 5:45 PM

Thanks genbox, just FYI - I tried 100 and 1000 iterations and the problem still occurred, although it did happen slighlty differently and was slower to happen.

Aug 23, 2009 at 2:52 AM

I don’t mean to contradict genbox but i have found that going above 20 iterations actually made the engine more erratic and it seemed to overdo the calculations (this was for a stacking thing I was doing)
I found that the default iteration count of 5 was too low for stacking and anything over 20 was too high... I found that 15 seemed to work the best for my scenario.

Anyway you may find that 15 or so is good for you. Then again i could have been doing something weird.