Game Development Reference
In-Depth Information
Figure 14.5
A cross product and a dot product together can find a target.
cross product between the direction vectors contains information about which way to
steer.
The cross product between the target vector and your direction vector points up, indi-
cating you should steer right (see Figure 14.5). If the cross product pointed down, the
target would have been off to your left. The target example is somewhat contrived
because you don ' t actually need the cross product at all. It makes a good example
because it
'
s a useful experiment to visualize the usefulness of the cross product.
Find Targets with Just a Dot Product
Through a little trickery, you can do it solely with the dot product, as long as
you choose the correct vectors. If you use a vector that points to your right
instead of straight ahead, your dot product will yield a positive number if
you need to steer right, a negative number if you need to steer left, and
something close to zero if your target is right in front of you. Even better, if
your steering parameters range from
1.0 to steer hard left and 1.0 to lock it
all the way to the right, you can send this dot product straight into your
steering code. Cool, huh?
 
Search WWH ::




Custom Search