Game Development Reference
In-Depth Information
This is the rotating arm, part of the morning star. It has been created as
a standalone body as it will be pinned to the trailer's vertical arm with a
revolute joint.
var armJoint:b2RevoluteJointDef;
armJoint=new b2RevoluteJointDef();
armJoint.bodyA=body;
armJoint.bodyB=arm;
armJoint.localAnchorA.Set(0,-115/worldScale);
armJoint.localAnchorB.Set(0,0);
armJoint.enableMotor=true;
armJoint.maxMotorTorque=1000;
armJoint.motorSpeed=6;
var siege:b2RevoluteJoint;
siege=world.CreateJoint(armJoint) as b2RevoluteJoint;
And here is the revolute joint itself. It has a motor to allow the morning star
to rotate.
var projectileX:Number=(pX-80)/worldScale;
var projectileY:Number=(pY-115)/worldScale;
bodyDef.position.Set(projectileX,projectileY);
polygonShape.SetAsBox(5/worldScale,5/worldScale);
fixtureDef.shape=polygonShape;
fixtureDef.filter.categoryBits=0x0004;
fixtureDef.filter.maskBits=0x0004;
var projectile:b2Body=world.CreateBody(bodyDef);
projectile.CreateFixture(fixtureDef);
The projectile—the body which will be launched by the siege machine, the
head of the morning star— will be bound to the arm body with a distance joint.
slingJoint=new b2DistanceJointDef();
slingJoint.bodyA=arm;
slingJoint.bodyB=projectile;
slingJoint.localAnchorA.Set(-40/worldScale,0);
slingJoint.localAnchorB.Set(0,0);
slingJoint.length=40/worldScale;
sling=world.CreateJoint(slingJoint) as b2DistanceJoint;
And finally the distance joint that completes the morning star. Everything
seems easy but you shouldn't have missed the following two lines in the
creation of the vertical arm:
fixtureDef.filter.categoryBits=0x0002;
fixtureDef.filter.maskBits=0x0002;
 
Search WWH ::




Custom Search