Game Development Reference
In-Depth Information
nates of each craft's center of gravity. In terms of vectors, this is simply the position
vector of one craft minus the position vector of the other.
Once the function has d and r , it needs to determine the actual amount of space, s ,
separating the hovercraft's bounding circles. After this separation is determined, the
function normalizes the vector d . Since the vector d is along the line that separates the
hovercraft's centers of gravity, normalizing it yields the collision normal vector that we
need for our collision response calculations. The collision normal vector is saved in the
global variable vCollisionNormal .
After calculating the collision normal, this function goes on to determine the relative
velocity between the hovercraft. In vector form, this is simply the difference between
the velocity vectors of each craft. Note that the velocity vectors used here must be in
global coordinates, not body-fixed (local) coordinates. Since what's really needed to
determine if a collision is made is the relative normal velocity, the function proceeds to
take the vector dot product of the relative velocity and the collision normal vectors,
saving the result in the variable Vrn .
At this point, all of the calculations are complete, and the only thing left to do is make
the appropriate checks to determine if there is a collision, penetration, or no collision
at all.
The first check is to see if the hovercraft are colliding. We determine this by comparing
the absolute value of the separation between the hovercraft, s , with a distance tolerance,
ctol . If the absolute value of s is less than ctol , a collision might be occurring. The
second requirement is that the relative normal velocity be negative, which implies that
the points of impact on the hovercraft are moving toward each other. If there is a col‐
lision, the function returns a 1 to indicate that collision response is necessary.
If the hovercraft are found not to be colliding, then we perform a second check to see
if they've moved so close together that they are penetrating each other. In this case, if s
is less than -ctol , the hovercraft are penetrating and the function returns a −1 . If the
hovercraft are not colliding and not penetrating, then the function simply returns a 0 ,
indicating that no further action is required.
Before moving on, let's say a word or two about ctol —the collision tolerance distance.
This value is subject to tuning. There's no single value that works well in all cases. You
must consider the overall sizes of the objects potentially colliding, the step size you're
using, and how far the colliding objects are from the viewer while being rendered (i.e.,
their scale). Basically, you should choose a value that makes collisions look correct, so
that on the one hand objects do not appear to be penetrating each other, and on the
other hand you do not report a collision when objects do not appear to be touching at
all.
Search Nedrilad ::




Custom Search