Game Development Reference
In-Depth Information
2.
The PreSolve function at the moment has the same code as BeginContact
and EndContact , but the code is executed only if the following if statement
is true:
if (contact.GetManifold().m_pointCount>0) {
3.
Box2D groups contact points into a manifold structure. The PreSolve
function is sometimes called even if the contact points aren't there in the
manifold, so this time we want it to be executed only if there is at least one
contact point.
override public function PostSolve(contact:b2Contact,
impulse:b2ContactImpulse):void {
trace("a collision has been post solved");
var fixtureA:b2Fixture=contact.GetFixtureA();
var fixtureB:b2Fixture=contact.GetFixtureB();
var bodyA:b2Body=fixtureA.GetBody();
var bodyB:b2Body=fixtureB.GetBody();
trace("first body: "+bodyA.GetUserData());
trace("second body: "+bodyB.GetUserData());
trace("impulse: "+impulse.normalImpulses[0]);
trace("---------------------------");
}
4.
The PostSolve function also has the same code as the other functions, with
the exception of the following line:
trace("impulse: "+impulse.normalImpulses[0]);
As you can see, the PostSolve function has an impulse passed as an
argument. The normalImpulses property of a b2ContactImpulse object
returns a vector with all impulses generated by the collisions. We are looking
for the first and only impulse, which in other words represents the strength
of the collision.
5. Test the movie again, and every time the ball bounces on the floor, you
should see the following output text:
a collision started
first body: Floor
second body: Ball
---------------------------
a collision has been pre solved
first body: Floor
second body: Ball
 
Search WWH ::




Custom Search