This project has moved and is read-only. For the latest updates, please go here.

Shapes are always moving and jiggling so they cant get inertia

Jun 10, 2009 at 5:59 AM

Hi There!!!

Nice Physics Engine but i have a question.. iam learning the basics on Advanced farsee physics Engine Examples for XNA

and i notice that shapes always are moving so they cant get "Calm" so if u wait like 5 min the stacked squares just move to the edge and fall

How can i do to "get on calm" my shapes????.. MomentOfInertia Value?????



Jun 10, 2009 at 6:11 AM

Well there are a few things you can do


These are things i have found from my experiance...


·         Set the engine to have a few more iterations (10 seems good)
You can do this by setting (PhysicsSimulator.Iterations = 10;)

·         Fiddiling with the values of the engine itself
Done like this
PhysicsSimulator.BiasFactor = 0.3f;

PhysicsSimulator.MaxContactsToDetect = 4;

PhysicsSimulator.MaxContactsToResolve = 2;

PhysicsSimulator.AllowedPenetration = 0.1f;

·         Now then there is the thing that will work the best.. But it is also the hardest to get working
It is the interactivity controller and it can also make you simulation run much much faster when things are resting. But it takes ALOT of tweaking. This is how you start.

PhysicsSimulator.InactivityController.ActivationDistance = 200;
PhysicsSimulator.InactivityController.MaxIdleTime = 500;
PhysicsSimulator.InactivityController.Enabled = true;

These settings are what i use they should get you going also make sure to set activation distance a bit larger than you largest body in the game.

·         Also try to (if you can) keep your stacks under 8 or 9 high

Hope all this helps in getting you started.

Jun 10, 2009 at 10:00 AM

The SAT narrow-phase collider fixes this issue. The 2.1 release is just days away and the updated manual will let you know how to use SAT.

Jun 10, 2009 at 6:18 PM
Edited Jun 10, 2009 at 6:19 PM

As danthekilla said, you can adjust the settings of the engine to improve stability.
Just wanted to give some details of why changing the settings help.

The engine itself uses the Sequential Impulse method created by Erin Catto (from Box2D). This means that instead of calculating everything perfect the first time (which is really expensive = low performance) we simple approximate the perfect solution by iterating the engine and calculate everything in each iteration instead. Let's take an example:

If you have a chain of geometries where each body is connected to the next by a joint. The engine iterate each and every body, apply gravity and finds collision points (contacts). Then it calculate the impulse required to separate each geometry to make sure it looks like they are colliding.
The engine does not take the first body, calculate it's impulse, take the next body and take the first body's impulse into account. It simple takes each body without knowing of any other body's impulse.

This is not very precise in a single iterate and the simulation will probably be unstable, but if we save the error created in each iterate, the error value will be lower and lower in each iteration and we will finally eventually converge to the perfect solution (Or very close to it anyway).
Having a demo like the pyramid requires the engine to be very accurate and stable. To make it more accurate, you simply give it a higher iteration count (or tweak the other setting presented by danthekilla). I hope that gives some insight on how the engine works and why this happens.

Jun 10, 2009 at 8:33 PM

ye i did what danthekilla saids and still doing the same "error" i notice if u increase the processor thread the physics looks more Realistic just the "error" of the stability....

what did u said about 2.1 release??? i read something on source code about some fix that makes the engine to 2.1...

Thanks all

Jun 10, 2009 at 8:59 PM

Ok... the stabilty was improved on the source code Update...(Download on source code the link with the description: "Updating all AssemblyInfo.cs files to be version 2.1 and have correct description") but now if i increase the line:


_physicsSimulator.Update(Math.Min(_iterateParam.GameTime.ElapsedGameTime.Milliseconds, 100)*.001f);


_physicsSimulator.Update(Math.Min(_iterateParam.GameTime.ElapsedGameTime.Milliseconds, 100)*.003f);

(this change makes the physics looks very realistic(fast) but it decrease the stability)

the new question is.... How can i keep my stabilty and dont loose the fast perfomance???