如何在 Box2D 中创建一个以中心旋转的平台体

发布于 2024-10-18 20:13:49 字数 283 浏览 6 评论 0原文

我正在尝试创造漂浮在太空中的旋转形状。环境中仍然存在重力,但它不应该影响这些平台对象,因为它们是静态的(对吗?)。我如何对其应用恒定的角速度?当我给它赋值时,它似乎不适用,可能是因为它是静态的。

最简单的例子是一个旋转齿轮,一个自动跷跷板(不受外力影响)。我想做的只是一个旋转的矩形,它可能会干扰用户控制的球。

我需要使用接头将其固定到位吗?如何指定不受动态对象影响的细节?

感谢任何对此有答案的人!

I'm trying to create spinning shapes floating in space. There is still gravity in the environment, however it should not affect these platform objects because they are static (right?). How can I apply a constant angularVelocity to it though? It doesn't seem to apply when I assign it a value, probably due because it's static.

The simplest example would be a spinning gear, an automated teeter-totter (not influenced by external forces). All I'm trying to make is a spinning rectangle that could interfere with a ball controlled by the user.

Do I need to use Joints to pin it in place? How can I specify the details of not being influenced by the dynamic objects?

Thanks for anyone who has an answer to this!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离线来电— 2024-10-25 20:13:49

实际上,找到了一个很棒的资源网站,其中显示了一些常见的示例:
http://blog.thestem.ca/archives/102

需要注意的重要一点是,联合本身几乎没有什么用处(或者甚至只附加一个 b2Body)。

它始终需要两 (2) 个主体与其 .body1 和 .body2 属性关联。因此,为了将对象“固定”到世界/背景,您必须创建一个“虚拟”主体作为两个候选主体之一,而另一个则是您想要的移动对象。 电机速度和扭矩是使其“旋转”的关键,而不是在更新方法中控制角速度或直接操纵主体的角度。

var pivotDef:b2BodyDef =    new b2BodyDef();
pivotDef.position.SetV( _b2body.GetWorldCenter() );
_b2bodyPivot =  b2WorldInst.CreateBody( pivotDef );

var jointDef:b2RevoluteJointDef =   new b2RevoluteJointDef();
jointDef.Initialize( _b2bodyPivot, _b2body, _b2bodyPivot.GetPosition() );
jointDef.motorSpeed =       1;
jointDef.maxMotorTorque =   10000000;
jointDef.enableMotor =      true;
jointDef.enableLimit =      false;

var joint:b2RevoluteJoint = b2WorldInst.CreateJoint( jointDef )  as b2RevoluteJoint;

——

希望这可以为其他 Flash 物理学家节省一些时间来解决这个问题:)

Actually, found a great resource site showing an example of a few common ones:
http://blog.thestem.ca/archives/102

An important thing to notice, a joint is pretty much useless by itself (or even with only a single b2Body attached to it).

It always require two (2) bodies to be associated to it's .body1 and .body2 properties. So in order to "pin" an object to the world / background, you have to create a "dummy" body as one of the two body candidates, while the other would be your desired moving object. The motor speed and torque is the key to make it "spin", as opposed to controlling the angularVelocity or directly manipulating the body's angle in an update method.

var pivotDef:b2BodyDef =    new b2BodyDef();
pivotDef.position.SetV( _b2body.GetWorldCenter() );
_b2bodyPivot =  b2WorldInst.CreateBody( pivotDef );

var jointDef:b2RevoluteJointDef =   new b2RevoluteJointDef();
jointDef.Initialize( _b2bodyPivot, _b2body, _b2bodyPivot.GetPosition() );
jointDef.motorSpeed =       1;
jointDef.maxMotorTorque =   10000000;
jointDef.enableMotor =      true;
jointDef.enableLimit =      false;

var joint:b2RevoluteJoint = b2WorldInst.CreateJoint( jointDef )  as b2RevoluteJoint;

--

Hopefully that saves other Flash physicists some time to figure this one out :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文