Game Development Reference
In-Depth Information
To solve this first issue, we need to find the precise point in time that the asteroids
intersect, even if it occurs between frames. Because the asteroids use bounding
spheres,wecanusesweptsphereintersectiontofindtheexacttimeofintersection.
Once we find the time of intersection, we must roll back the position of the two
spheres to that point in time. We can then apply whatever change to the velocity
we want (in our naïve case, negate them) and then complete the rest of the time
step with the new velocity.
However, there's still a big problem with our collision response: Negating the ve-
locities is not the correct behavior. To see why this is the case, imagine you have
two asteroids travelling in the same direction, one in front of the other. The front
asteroid is travelling slower than the back asteroid, so eventually the back asteroid
willcatchup.Thismeanswhenthetwoasteroidsintersect,theywillbothsuddenly
start travelling in the opposite direction, which definitely is not correct.
So rather than negating the velocity, we actually want to reflect the velocity vector
based on the normal of the plane of intersection. This uses the vector reflection
concept discussed in Chapter 3 . If an asteroid were colliding with a wall, it would
beeasyenoughtofigureouttheplane ofintersection because wecanmake aplane
out of the wall. However, in the case of two spheres touching at precisely one
point, we need to find the plane that's tangential to the point of intersection, as in
Figure 7.13(b) .
To construct this tangential plane, we first need to determine the point of intersec-
tion. This can actually be done using linear interpolation. If we have two spheres
that are touching at one point, the point ends up being somewhere on the line seg-
ment between the center of the two spheres. Where it is on that line segment de-
pends on the radii of the spheres. If we have two instances of BoundingSphere
A and B that are intersecting at precisely one point, we can calculate the point of
intersection using linear interpolation:
Click here to view code image
Vector3 pointOfIntersection = Lerp( A . position ,
B . position ,
A . radius /
( A . radius + B . radius ))
It turns out the normal of this tangential plane is simply the normalized vector
from the center of one sphere to the center of the other. With both a point on the
plane and a normal, we can then create the plane that's tangential at the point of
Search WWH ::




Custom Search