Search code examples
androidbox2dandengine

AndEngine rotate all connected bodies


I have created below hexagon structure in Andengine with Box2D physics engine. I want to rotate whole structure with respect to center when other ball collides with the structure using physics.

find reference image here : reference question

I tried weld joint and revolute joint with the bodies but it is not performing proper motion as required. All bodies are attached with weld joint and vertices have revolute joint with center body which is static like,

RevoluteJointDef revoluteJointDef1 = new RevoluteJointDef();
revoluteJointDef1.initialize(centerB, movingBody[i], centerB.getWorldCenter());
revoluteJointDef1.enableMotor = true;
revoluteJointDef1.motorSpeed = 0;
revoluteJointDef1.maxMotorTorque = 1f;
this.mPhysicsWorld.createJoint(revoluteJointDef1);

Is there any other way to perform smooth rotation of whole structure? Thanks.


Solution

  • Oh! i got solution by myself... I did the same thing as i mentioned in first comment my question where I attached balls on a big circle body like,

    Body circleBody ... ;// having large radius
    //for all balls arranged in hexagon structure
    foreach BallBody b
    {
    WeldJointDef def = new WeldJointDef();
    def.initialize(b, circleBody, b.getWorldCenter());
    mPhysicsWorld.createJoint(def);
    }
    

    and got the rotation by having revolute joint of circleBody with center. Thanks who put their efforts.