box2d - box2djs 中的 Spring 效果

标签 box2d box2dweb

我想使用 box2djs 模拟 Spring 效果。
经过大量搜索,我认为可以使用该距离关节(我不确定)。
我尝试了以下代码,但我看不到 body 之间的任何关节。

 distance_joint = new b2DistanceJointDef();

distance_joint.body1 = Body1;

distance_joint.body2 = Body2;

distance_joint.localAnchorA = new b2Vec2(0, 0);

distance_joint.localAnchorB = new b2Vec2(0, 0);

distance_joint.length = 3;

distance_joint.collideConnected = true;

return world.CreateJoint(distance_joint); 

任何的想法...

谢谢

最佳答案

你说得对,距离接头可以用作 Spring 。这是在 Box2D 手册中说的:

The distance joint can also be made soft, like a spring-damper connection. See the Web example in the testbed to see how this behaves.

Softness is achieved by tuning two constants in the definition: frequency and damping ratio. Think of the frequency as the frequency of a harmonic oscillator (like a guitar string). The frequency is specified in Hertz. Typically the frequency should be less than a half the frequency of the time step. So if you are using a 60Hz time step, the frequency of the distance joint should be less than 30Hz. The reason is related to the Nyquist frequency.

The damping ratio is non-dimensional and is typically between 0 and 1, but can be larger. At 1, the damping is critical (all oscillations should vanish).

jointDef.frequencyHz = 4.0f;
jointDef.dampingRatio = 0.5f;

关于box2d - box2djs 中的 Spring 效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14746312/

相关文章:

java - 对 box2d 主体施加力不起作用

objective-c - 使用 C++ 库的 XCode 4 自动完成?

java - LibGDX,我应该如何在屏幕和舞台内组织代码?

javascript - Box2dweb 禁止移动

kineticjs - 在 KineticJS 中使用变换矩阵

javascript - 在javascript中确定移动设备上的哪个方向朝下?

Libgdx box2d body 移动缓慢

java - 如何将 Sprite 添加到 Box2d Body?