Game Development Reference
In-Depth Information
We need to determine two different things in order to perform a smooth transition.
First, we need the angle between the current facing vector and the new facing vec-
tor of the player. Once we have that, we then need to figure out whether the char-
acter should rotate clockwise or counterclockwise. Figure 3.10 presents a visual-
ization of this problem.
Figure 3.10 The player needs to rotate to face the explosion.
The vector c y represents the current direction the player is facing. P is the position
of the player in the world, and E is the position of the explosion. The first step to
solve this problem is to construct a vector that points in the direction of the explo-
sion. We want the vector from P to E , so the calculation should be E - P . Because
we only care about the direction in this problem, and not the distance, we should
go ahead and normalize this vector. Therefore, we can define as the unit vector
that points in the direction of the explosion.
Now that we have the current and new directions, how do we find the angle
between the two vectors? The answer is the dot product. Because both and are
unit vectors, the angle θ can be calculated with
.
Search WWH ::




Custom Search