[英]How can I make my physics object settle down?
I'm using BulletSharp, a C# distribution of the bullet library. 我正在使用BulletSharp,它是子弹库的C#发行版。 I have been getting some bouncing in an object that supposedly has Restitution of 0.0f.
我已经在一个据称有0.0f的恢复原状的物体中得到了一些弹跳。
I have one dynamic cylinder (what will be a mesh soon) falling to rest on two static cylinders. 我有一个动态气缸(不久将是一个网状物)落在两个静态气缸上。 Like so:
像这样:
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);
每一帧我都使用
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. 小更新:我已成功在Blender的Bullet中进行类似的模拟。 There was no bouncing there... I don't know what difference there might be between that and this.
那里没有弹跳......我不知道那和那之间可能有什么不同。
You didn't add Inertia into your model. 您没有将Inertia添加到模型中。 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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.