Game Development Reference
In-Depth Information
Upon closer inspection, you'll notice that all four collision callback methods take the
same parameters as input, and two of them return a BOOL. Following is a list that ex-
plains under which circumstances and in which order each of these methods is called:
Begin
methods are called when two bodies first come into contact. It's al-
ways the first method called in a collision event between two bodies. By re-
turning
NO
, the collision is ignored, bodies are allowed to pass through each
other, and
PreSolve
and
PostSolve
methods for this collision event
will not be called.
PreSolve
methods get called repeatedly for as long as two bodies are in con-
tact, and before the collision has been resolved. This allows you to tweak the
collision response by (temporarily) modifying the contacting body's proper-
ties, such as friction or restitution. Returning
NO
will not resolve the colli-
sion so that the two bodies are allowed to penetrate for this particular point
in time.
PostSolve
methods get called after the collision has been resolved, meaning
the bodies have been moved apart and their velocities updated.
PostSolve
can be used to reset any temporarily modified properties from the
PreSolve
step. But more importantly, other collision-based properties like
totalKineticEnergy
and
totalImpulse
have now been calculated.
This allows you to break joints or play sounds as necessary, perhaps when
the impact force exceeds a given threshold.
Separate
methods get called the moment two previously contacting bodies
are no longer in contact.
Tip
A
Begin
method is always followed by a corresponding
Separate
method, even if the
Begin
method returned
NO
. You can rely on counting the
number of
Begin
and
End
calls to determine how many, or if any, two bodies
of the given collision types are currently in contact with each other.
Collision Types and Callback Parameter Names
The collision callback methods in
Listing 4-12
all take the same parameters as input. The
names of the
collisionTypeA
and
collisionTypeB
parameters actually play an
Search WWH ::
Custom Search