Game Development Reference
In-Depth Information
5.
As we are using a custom contact listener, we'll disable collisions between the
projectile and the siege machine using the customContact class.
6.
Finally, the updateWorld must also be changed to include the lines to remove
destroyed bodies.
private function updateWorld(e:Event):void {
if (left) {
motorSpeed-=0.1;
}
if (right) {
motorSpeed+=0.1;
}
motorSpeed*0.99;
if (motorSpeed>5) {
motorSpeed=5;
}
if (motorSpeed<-5) {
motorSpeed=-5;
}
frj.SetMotorSpeed(motorSpeed);
rrj.SetMotorSpeed(motorSpeed);
world.Step(1/30,10,10);
world.ClearForces();
for (var b:b2Body=world.GetBodyList(); b; b=b.GetNext())
{
if (b.GetUserData()=="remove") {
world.DestroyBody(b);
}
}
world.DrawDebugData();
}
7.
And last but not the least, something new to learn about collisions. The
following is how I am using the PreSolve callback function to determine
if the cart collided with the projectile and disable the collision before the
contact is solved, adding this function to the customContact class:
override public function PreSolve(contact:b2Contact,
oldManifold:b2Manifold):void {
var fixtureA:b2Fixture=contact.GetFixtureA();
var fixtureB:b2Fixture=contact.GetFixtureB();
var dataA:String=fixtureA.GetBody().GetUserData();
var dataB:String=fixtureB.GetBody().GetUserData();
if (dataA=="cart" && dataB=="projectile") {
contact.SetEnabled(false);
 
Search WWH ::




Custom Search