将两个 box2D 主体牢固地固定在一起

发布于 2024-12-20 08:59:33 字数 641 浏览 3 评论 0原文

我正在尝试将两个相隔固定距离的 box2d 主体连接在一起。两个实体都不能自行旋转,并且连接也必须旋转。物体之间的间隙需要允许其他物体通过。

我目前有一个 b2revoluteJoint 设置,如下所示:

b2RevoluteJointDef rjd;
rjd.lowerAngle = 0.0f;
rjd.upperAngle = 0.0f;
rjd.Initialize(body2, body1, body2->GetPosition());
rjd.collideConnected = false;
world->CreateJoint(&rjd);

但是,关节并不完全刚性,并且身体往往会相对于彼此移动相当大的距离。有更好的方法吗?

我也尝试过 b2WeldJoint ,但它不起作用,因为我假设两个物体必须重叠...

编辑:

我尝试过的 b2WeldJoint 是:

b2WeldJointDef wj;
wj.Initialize(body1, body2, body1->GetWorldCenter());
world->CreateJoint(&wj);

但是,当我移动一个物体时,另一个物体保持在其位置。

I am trying to join two box2d bodies together that are separated over a fixed distance. Both bodies cannot rotate themselves, and the join should have to rotation either. The gap between the bodies needs to allow other bodies to pass through.

I currently have a b2revoluteJoint setup like so:

b2RevoluteJointDef rjd;
rjd.lowerAngle = 0.0f;
rjd.upperAngle = 0.0f;
rjd.Initialize(body2, body1, body2->GetPosition());
rjd.collideConnected = false;
world->CreateJoint(&rjd);

However the joint is not completely rigid and the bodies tend to move around a fair bit relative to each other. Is there a better way to do this?

I have also tried the b2WeldJoint which did not work as I assume both bodies have to be overlapping...

EDIT:

The b2WeldJoint I have tried is:

b2WeldJointDef wj;
wj.Initialize(body1, body2, body1->GetWorldCenter());
world->CreateJoint(&wj);

However when I move one body, the other body stays in its position.

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

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

发布评论

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

评论(1

网白 2024-12-27 08:59:33

我还尝试了 b2WeldJoint,但它不起作用,因为我认为两个实体必须重叠......

据我所知,实体的形状不一定必须重叠。据我了解您的设置,焊接接头是合适的,因为它禁止所有相对平移和旋转。

I have also tried the b2WeldJoint which did not work as I assume both bodies have to be overlapping...

As far as I know, the shapes of the bodies do not necessarily have to overlap. As far as I have understood your setup, the weld joint would be appropriate, since it forbids all relative translation and rotation.

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