Fixing two box2D bodies together securely

有些话、适合烂在心里 提交于 2019-12-02 11:39:13

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/8434188/fixing-two-box2d-bodies-together-securely

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!