How can I make my physics object settle down?
Asked Answered
S

1

9

I'm using BulletSharp, a C# distribution of the bullet library. I have been getting some bouncing in an object that supposedly has Restitution of 0.0f.

I have one dynamic cylinder (what will be a mesh soon) falling to rest on two static cylinders. Like so:

starting object positions

The cylinder on top often bounces around wildly, usually bouncing off to the side.

Here's the code I'm using to set up the scene:

        //now figure out bulletsharp stuff...
        CollisionConfiguration collConfig = new DefaultCollisionConfiguration();
        Dispatcher collDispatch = new CollisionDispatcher(collConfig);

        BroadphaseInterface broadphase = new DbvtBroadphase();
        ConstraintSolver sol = new SequentialImpulseConstraintSolver();
        world = new DiscreteDynamicsWorld(collDispatch, broadphase, sol, collConfig);

        world.Gravity = new Vector3(0.0f, -10.0f, 0.0f);

        //log (moving object)
        MotionState still = new DefaultMotionState();
        CylinderShape shape = new CylinderShapeZ(0.5f, 1.0f, 1.0f);
        still.WorldTransform = Matrix.Translation(0.0f, 0.4f, 0.0f);
        RigidBodyConstructionInfo constructInfo = new RigidBodyConstructionInfo(1.0f, still, shape);
        logBody = new RigidBody(constructInfo);
        logBody.SetDamping(0.04f, 0.1f);
        world.AddRigidBody(logBody);

        //rollers (static objects)
        CylinderShape r1s = new CylinderShapeZ(0.1f, 1.0f, 1.0f);
        MotionState r1m = new DefaultMotionState();
        r1m.WorldTransform = Matrix.Translation(-0.2f, -0.4f, 0.0f);
        RigidBodyConstructionInfo r1ci = new RigidBodyConstructionInfo(0.0f, r1m, r1s);
        r1 = new RigidBody(r1ci);
        world.AddRigidBody(r1);

        CylinderShape r2s = new CylinderShapeZ(0.1f, 1.0f, 1.0f);
        MotionState r2m = new DefaultMotionState();
        r2m.WorldTransform = Matrix.Translation(0.2f, -0.4f, 0.0f);
        RigidBodyConstructionInfo r2ci = new RigidBodyConstructionInfo(0.0f, r2m, r2s);
        r2 = new RigidBody(r2ci);
        world.AddRigidBody(r2);

And every frame I use world.StepSimulation(0.05f, 100, 0.0005f); to update the physics simulation.

Am I missing any obvious settings? Why is my simulation doing this?

Small update: I have successfully made a similar simulation in Blender's Bullet stuff. There was no bouncing there... I don't know what difference there might be between that and this.

Schriever answered 28/5, 2012 at 20:25 Comment(2)
Can you add restitution to the falling object?Rockel
Adding restitution to only the falling object didn't make any appreciable difference. Setting restitution to 0.1 for all three objects seemed to settle it down a bit, but depending on the simulation step size. There was still a bit of bouncing, occasionally bouncing off.Schriever
P
4

You didn't add Inertia into your model. That should slow down the jittering and should not produce the reverb that ends in it bouncing off the rollers. You'll need to add it for all three objects including the Zero on the rollers. Try this and let me know how it works:

//now figure out bulletsharp stuff...
CollisionConfiguration collConfig = new DefaultCollisionConfiguration();
Dispatcher collDispatch = new CollisionDispatcher(collConfig);

BroadphaseInterface broadphase = new DbvtBroadphase();
ConstraintSolver sol = new SequentialImpulseConstraintSolver();
world = new DiscreteDynamicsWorld(collDispatch, broadphase, sol, collConfig);

world.Gravity = new Vector3(0.0f, -10.0f, 0.0f);

//log (moving object)
Vector3 cylinderInertia;
MotionState still = new DefaultMotionState();
CylinderShape shape = new CylinderShapeZ(0.5f, 1.0f, 1.0f);
still.WorldTransform = Matrix.Translation(0.0f, 0.4f, 0.0f);
shape.CalculateLocalInertia(1.0f, out cylinderInertia);    
RigidBodyConstructionInfo constructInfo = new RigidBodyConstructionInfo(1.0f, still, shape, cylinderInertia);
logBody = new RigidBody(constructInfo);
logBody.SetDamping(0.04f, 0.1f);
world.AddRigidBody(logBody);

//rollers (static objects)
CylinderShape r1s = new CylinderShapeZ(0.1f, 1.0f, 1.0f);
MotionState r1m = new DefaultMotionState();
r1m.WorldTransform = Matrix.Translation(-0.2f, -0.4f, 0.0f);
RigidBodyConstructionInfo r1ci = new RigidBodyConstructionInfo(0.0f, r1m, r1s, Vector3.Zero);
r1 = new RigidBody(r1ci);
world.AddRigidBody(r1);

CylinderShape r2s = new CylinderShapeZ(0.1f, 1.0f, 1.0f);
MotionState r2m = new DefaultMotionState();
r2m.WorldTransform = Matrix.Translation(0.2f, -0.4f, 0.0f);
RigidBodyConstructionInfo r2ci = new RigidBodyConstructionInfo(0.0f, r2m, r2s, Vector3.Zero);
r2 = new RigidBody(r2ci);
world.AddRigidBody(r2);
Privity answered 3/6, 2012 at 3:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.