简体   繁体   English

使阻尼比率与 Box2D 和 DistanceJoint 一起使用

[英]Getting dampingRatio to work with Box2D and DistanceJoint

I have tried unsuccessfully on several projects to get a distance joint to stop swinging forever in Box2D for JavaScript.我曾在几个项目中尝试获得一个距离关节以在 Box2D for JavaScript 中永远停止摆动,但都没有成功。 No matter what values I set for the density of the bodies and the dampingRatio and frequencyHz of the distant joint definition - the result is you pick up one end and the other end swings endlessly.无论我为物体的密度以及远处关节定义的阻尼比和频率赫兹设置了什么值 - 结果都是你拿起一端而另一端无休止地摆动。 I want the swing to get smaller and then stop after a few swings.我希望摆动变小,然后在几次摆动后停止。

// I have made a world and bodies with density of 1 (although I have tried bigger)
var distanceJointDef = new b2DistanceJointDef();
distanceJointDef.Initialize(circleBody, triBody, circleBody.GetWorldCenter(), triBody.GetWorldCenter());
distanceJointDef.dampingRatio = 1; // tried .5, 20, etc. no difference
distanceJointDef.frequencyHz = 30; // tried all sorts of numbers
world.CreateJoint(distanceJointDef);

The joint works - but the damping does not.关节起作用 - 但阻尼不起作用。 Any help would be appreciated.任何帮助,将不胜感激。 Here is a link to the Box2D I am using: https://github.com/joelgwebber/bench2d/tree/master/js/Box2dWeb-2.1a.3这是我正在使用的 Box2D 的链接: https : //github.com/joelgwebber/bench2d/tree/master/js/Box2dWeb-2.1a.3

The answer is to put linear damping on the objects you are swinging.答案是对你正在摆动的物体施加线性阻尼。 var definition = new b2BodyDef(); var 定义 = new b2BodyDef(); definition.linearDamping = .5;定义.线性阻尼 = .5; // etc. where numbers towards 1 slow quickly // 等等,其中数字向 1 变慢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM