Game Development Reference
In-Depth Information
And the following two too during the creation of the projectile:
fixtureDef.filter.categoryBits=0x0004;
fixtureDef.filter.maskBits=0x0004;
You already know that bodies pinned with a revolute joint do not collide.
Unfortunately the projectile is not a part of the revolute joint and will collide
with the vertical arm, so the morning star would not work, unless we find a
way to prevent vertical arm and projectile collision.
Box2D features collision filtering , which allows you to prevent collision
among fixtures. Collision filtering allows us to put fixtures in categories with
the categoryBits property. This way, more fixtures can be placed in one
big group. Then, you need to specify for every group which groups they are
allowed to collide with, using masking bits.
In the last four lines of code we just saw, the trailer and the projectile are
placed into different categories whose masking bits only allow collisions
among fixtures inside the same category, so the projectile and the vertical
arm will never collide, allowing the morning star to rotate freely. This way,
the projectile won't even collide with the ground, but we'll fix it in a minute.
3. One last thing, the player will be able to fire the projectile by destroying the
distance joint once the up arrow key is pressed, so we are adding another
case in the switch statement in the keyPressed function:
private function keyPressed(e:KeyboardEvent):void {
switch (e.keyCode) {
case 37 :
left=true;
break;
case 39 :
right=true;
break;
case 38 :
world.DestroyJoint(sling);
break;
}
}
The DestroyJoint method removes a joint from the world.
 
Search WWH ::




Custom Search