gpt4 book ai didi

box2d - box2djs 中的 Spring 效果

转载 作者:行者123 更新时间:2023-12-01 01:12:17 24 4
gpt4 key购买 nike

我想使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com