简体   繁体   English

如何让我的物理对象安定下来?

[英]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.

相关问题 如何使 object 漂浮/停留在空中而不掉落? - How can I make an object float/stay in the air and not falling down? 我如何使对象将不停地自动向上/向下缩放? - How can I make that the object will scale automatic up/down nonstop? Unity物理学-如何使物体像重力一样在空间中上下摆动? - Unity physics - how to make objects bob down then up as if in space with gravity? 我怎样才能实现相同的物理学? - How can I realise the same physics? 按住按钮时如何让我的播放器连续移动? - How can i make my player continuously move when a button gets held down? ModelVisual 3D颠倒显示我的图像,如何使其正确? - ModelVisual 3D shows my image upside down, how can I make it proper? 如果玩家希望他们可以握住 animation,我该如何做到这一点,但如果他们不握住它,它就完成了..(基于物理) - How do I make it so if the player wants they can hold the animation but if they don't hold it, it completes.. (physics based) 如何多次快速按F可以平滑地缩放对象而无需等待? - How can I make that when pressing F fast many time it will scale the object down/up smooth without waiting? 如何在Unity 5中向对象添加物理 - How to add physics to an object in Unity 5 如何将多个对象集成到基于物理的单个刚体中? - How can I integrate multiple objects into a single physics based rigidbody?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM