将两个 box2D 主体牢固地固定在一起
我正在尝试将两个相隔固定距离的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,实体的形状不一定必须重叠。据我了解您的设置,焊接接头是合适的,因为它禁止所有相对平移和旋转。
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.