如何在适用于 Android 的 Box2d 中使用棱柱关节

发布于 2024-12-08 13:30:48 字数 885 浏览 8 评论 0原文

我是 Box2d 的新手,遇到的情况是我有两个主体。一种是静态的,另一种是动态的。我希望我的动态身体向下移动并返回并沿着同一条线撞击另一个身体。经过一些初步研究后,我考虑使用棱柱形接头。我研究了一些示例并在 onLoadScene() 中编写了一段代码。但什么都没有动。代码如下:

@Override
public Scene onLoadScene()
{
 .....
    PrismaticJointDef prismaticJointDef = new PrismaticJointDef();
    prismaticJointDef.initialize(bdy_holder, bdy_spring, bdy_holder.getWorldCenter(), new Vector2(1.0f, 0.0f));
    prismaticJointDef.lowerTranslation = -5.0f;
    prismaticJointDef.upperTranslation = 2.5f;
    prismaticJointDef.enableLimit = true;
    prismaticJointDef.maxMotorForce = 200.0f;
    prismaticJointDef.motorSpeed = 10.0f;
    prismaticJointDef.enableMotor = true;
    prismaticJointDef.collideConnected = true;

    prismatic_Joint = (PrismaticJoint)this.mPhysicsWorld.createJoint(prismaticJointDef);
}

现在我认为当我运行应用程序时,主体应该移动,但它们没有移动。我是全新的,无法弄清楚确切的问题。请指导我找到问题、解决方案和正确的使用示例。谢谢。

I am new to Box2d and have a situation where I have two bodies. One is static and the other is dynamic. I want my dynamic body to go down wards and come back and hit the other body along same line. I thought to use prismatic joint after some initial study. I have looked into some example and written a piece of code in onLoadScene(). But nothing is moving. Here is the code:

@Override
public Scene onLoadScene()
{
 .....
    PrismaticJointDef prismaticJointDef = new PrismaticJointDef();
    prismaticJointDef.initialize(bdy_holder, bdy_spring, bdy_holder.getWorldCenter(), new Vector2(1.0f, 0.0f));
    prismaticJointDef.lowerTranslation = -5.0f;
    prismaticJointDef.upperTranslation = 2.5f;
    prismaticJointDef.enableLimit = true;
    prismaticJointDef.maxMotorForce = 200.0f;
    prismaticJointDef.motorSpeed = 10.0f;
    prismaticJointDef.enableMotor = true;
    prismaticJointDef.collideConnected = true;

    prismatic_Joint = (PrismaticJoint)this.mPhysicsWorld.createJoint(prismaticJointDef);
}

Now I think the bodies should be moving when I run the application, but they are not movng. I am totally new and can't figure out the exact problem. Kindly guide me to the problem, solution and proper example of using this. Thanks.

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

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

发布评论

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

评论(1

未蓝澄海的烟 2024-12-15 13:30:48

尝试

prismaticJointDef.collideConnected = false;

try

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