将两个box2D实体牢固地固定在一起 [英] Fixing two box2D bodies together securely
问题描述
我正在尝试将两个box2d实体连接在一起,它们在固定距离上分开。两个实体都不能旋转,而连接也必须旋转。物体之间的空隙需要允许其他物体通过。
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.
我目前有一个b2revoluteJoint设置,如下所示:
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?
我也尝试了b2WeldJoint,该方法没有用,因为我认为两个物体必须重叠...
I have also tried the b2WeldJoint which did not work as I assume both bodies have to be overlapping...
编辑:
我尝试过的b2WeldJoint是:
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.
推荐答案
我还尝试了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.
这篇关于将两个box2D实体牢固地固定在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!