Controlling joints with motors

Some joints, such as the revolute joint feature motors, which in this case can be used to rotate the joint at a given speed unless a given maximum torque is exceeded.

Learning motors will allow you to develop every kind of car/truck game you see on the Web.

  1. To create the truck, we need to apply a motor on the rightmost cart, so in the addCart function we are adding an argument to tell us whether it should have a motor or not. Change the Main function to specify that frontCart will have a motor while rearCart won't:
    public function Main() {
      world=new b2World(new b2Vec2(0,5),true);
      debugDraw();
      ground();
      var frontCart:b2Body=addCart(200,430,true);
      var rearCart:b2Body=addCart(100,430,false); var dJoint:b2DistanceJointDef=new ...

Get Box2D for Flash Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.