# Box2D speed control issue using revolute joints

**URL:** https://discourse.processing.org/t/box2d-speed-control-issue-using-revolute-joints/18788
**Category:** Libraries
**Created:** [March 19, 2020, 9:53am UTC](https://discourse.processing.org/t/box2d-speed-control-issue-using-revolute-joints/18788 "2020-03-19T09:53:18Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![kenle](https://avatars.discourse-cdn.com/v4/letter/k/c37758/32.png) [@kenle](https://discourse.processing.org/u/kenle)
#### Post date: [March 19, 2020, 9:53am UTC](https://discourse.processing.org/t/box2d-speed-control-issue-using-revolute-joints/18788/1 "2020-03-19T09:53:18Z")

</div>

Hi there,

I cannot figure out how to control the motor speed of revolute joints from Box2D using processing.  
I use the same principle as Shiffman (youtube guru) creating a windmill (see partly code in the bottom). Here, he has a windmill that he toggles on and off, but it alway turns in only one direction with speed 2_PI. I simply just want to switch the direction to -2_PI ‘in game’. This should be done using “void SetMotorSpeed”, but I can’t seem to find the right syntax for applying that. I have tried to grab the joint as joint.SetMotorSpeed(-2\*PI) and a bunch of other approaches.

I sincerely hope for some help, so that I can continue building my robot with moving parts 🙂

\ Best regards

```auto
// Our object is two boxes and one joint
  // Consider making the fixed box much smaller and not drawing it
  RevoluteJoint joint;
  Box box1;
  Box box2;

  Windmill(float x, float y) {

    // Initialize locations of two boxes
    box1 = new Box(x, y-20, 120, 10, false); 
    box2 = new Box(x, y, 10, 40, true); 

    // Define joint as between two bodies
    RevoluteJointDef rjd = new RevoluteJointDef();

    rjd.initialize(box1.body, box2.body, box1.body.getWorldCenter());

    // Turning on a motor (optional)
    rjd.motorSpeed = PI*2; // how fast?
    rjd.maxMotorTorque = 1000.0; // how powerful?
    rjd.enableMotor = false; // is it on?

    // There are many other properties you can set for a Revolute joint
    // For example, you can limit its angle between a minimum and a maximum
    // See box2d manual for more
    

      // Create the joint
    joint = (RevoluteJoint) box2d.world.createJoint(rjd);
  }

  // Turn the motor on or off
  void toggleMotor() {
    joint.enableMotor(!joint.isMotorEnabled());
  }

  boolean motorOn() {
    return joint.isMotorEnabled();
  }

```
