模拟弹丸运动时如何处理旋转关节?

时间:2014-02-04 19:58:17

标签: libgdx box2d

我遇到了一些问题,我已经设置了用于启动箭头体的测试代码,所以我通过旋转关节将箭体贴在圆体上。并且我已经设置了一些用于发射箭头体的基本测试代码,但问题是,箭头体被卡在旋转关节上,箭体无法逃脱这个关节。我想知道这可能是什么解决方案。

我按一个按钮启动箭头,当按下按钮时箭头会移动。而且为了解决上述问题,我试图摧毁旋转体,但这并不是移动箭头的好方法。

有什么建议吗?

这是代码

revoluteJoint = new RevoluteJointDef();
    revoluteJoint.bodyA = rotatorBody;                          //defining the first body for the revolute joint 
    revoluteJoint.bodyB = arrowBody;                            //defining the second body for the revolute joint
    revoluteJoint.localAnchorB.set(0,0);                        //defining where you want the anchor point to be on the arrowbody
    revoluteJoint.collideConnected = false;                     //this is so that the relevant bodies can overlap
    revoluteJoint.enableMotor = true;                           //letting the joint move by itself
    revoluteJoint.maxMotorTorque = 250.0f;                      //maximum force
    revoluteJoint.motorSpeed = 0.0f;                            //speed is set to 0 so that the user can only move the arrow with touch
    world.createJoint(revoluteJoint);

buttonSTART.addListener(new InputListener(){
     @Override
     public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
             //game.setScreen(new Screenconfirmation(game));
        world.destroyBody(rotatorBody);
        arrowBody.setAwake(true);
        arrowBody.setGravityScale(1.0f);
        arrowBody.setAngularVelocity(0.0f);
        arrowBody.setTransform(arrowBody.getWorldPoint(new Vector2(3,0)), arrowBody.getAngle());
        arrowBody.setLinearVelocity(new Vector2(150,0));
             return true;
     }

});

0 个答案:

没有答案