title: Box2d spinning wheel with RevoluteJoint
body: <p>My goal is to make a wheel that slowly spins which should point where the gravity is. I'm developing this using libgdx for Android, when the device is rotated (I'm using the accelerometer) the wheel should spin.</p>
  <p>Here is the wheel made with the box2d-editor: <a href="https://i.stack.imgur.com/qYa0a.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qYa0a.png" alt="wheel" /></a></p>
  
  <p>In time = 0, the wheel points south, the gravity is (0, -10) so it should remain that way.. but it doesn't. As you can see in the picture provided the wheel slowly rotates CCW until it reaches a point which makes you think gravitity is like (10 , 0);</p>
  <p>My guess is that is has something to do with the mass center, but when I try to change that absolutely nothing happens.</p>
  <p>Here is some of the code:</p>
  <h2>The world</h2>
  <pre><code>world = new World( new Vector2(0, -10), false );
  </code></pre>
  <h2>The render</h2>
  <pre><code>public void render() {
      world.step(1/2f, 6, 2);
      debugRenderer.render(world, camera.combined);
  }
  </code></pre>
  <h2>The wheel creation</h2>
  <pre><code>    BodyDef engranajeBodyDef = new BodyDef();
      engranajeBodyDef.position.set(0,0);
      engranajeBodyDef.type = BodyType.DynamicBody;
      engranajeBodyDef.angularDamping = 0.1f;
      
      FixtureDef engranajeFixture = new FixtureDef();
      engranajeFixture.density = 10;
      engranajeFixture.friction = 0.1f;
      engranajeFixture.restitution = 0f;
      engranajeFixture.filter.groupIndex = -1;
      
      Body engranajeBody = world.createBody(engranajeBodyDef);
      
      bodyLoader.attachFixture(engranajeBody, &quot;engranaje&quot;, engranajeFixture, 501);
      
      RevoluteJointDef engranajeJointDef = new RevoluteJointDef();
      engranajeJointDef.bodyA = bgBody;
      engranajeJointDef.bodyB = engranajeBody;
      engranajeJointDef.collideConnected = false;
      engranajeJointDef.localAnchorA.set(0, 0);
      engranajeJointDef.localAnchorB.set(0, 0);
      
      world.createJoint(engranajeJointDef);
  </code></pre>
  <h2>The dummy body where the wheel is attached to</h2>
  <pre><code>    BodyDef bgBodyDef = new BodyDef();
      bgBodyDef.type = BodyType.StaticBody;
      bgBodyDef.position.set(0,0);
      
      bgBody = world.createBody(bgBodyDef);
      PolygonShape bgShape = new PolygonShape();
      //bgShape.setAsBox(camera.viewportWidth / 2, camera.viewportHeight / 2);
      bgShape.setAsBox(GAME_WIDTH,GAME_HEIGHT);
      
      bgBody.createFixture(bgShape, 1);
      bgShape.dispose();
  </code></pre>
  <p>This is where the wheel stops with gravity (0, -10) and the sprite I'm using to make this question more colorful :)</p>
  <p><a href="https://i.stack.imgur.com/Bk9Fj.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Bk9Fj.jpg" alt="wheel sprite" /></a></p>
  
  <p>Any help to understand this and point me in any direction will be much appreciated.</p>
  <p>Leandro.</p>