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.
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 theMain
function to specify thatfrontCart
will have a motor whilerearCart
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 b2DistanceJointDef(); dJoint.bodyA=frontCart; dJoint.bodyB=rearCart; dJoint.localAnchorA=new b2Vec2(0,0); dJoint.localAnchorB=new b2Vec2(0,0); dJoint.length=100/worldScale; var distanceJoint:b2DistanceJoint; distanceJoint...