Game Development Reference
In-Depth Information
dJoint.localAnchorB=new b2Vec2(0,0);
dJoint.length=100/worldScale;
var distanceJoint:b2DistanceJoint;
distanceJoint=world.CreateJoint(dJoint) as b2DistanceJoint;
addEventListener(Event.ENTER_FRAME,updateWorld);
}
13. And there's nothing new at the moment, but you were able to start building
your siege machine anyway. Test the movie:
Your carts now have wheels and are linked by a distance joint. Now we must
introduce something new to allow players to move the truck.
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);