Box2D speed control issue using revolute joints

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 2PI. I simply just want to switch the direction to -2PI ‘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 :slight_smile:

\ Best regards

// 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();
  }