Game Development Reference
In-Depth Information
X
NewForwardXZ
q
2
ForwardXZPlane
q
TurretToTarget
Target
Z
Figure 8-6.
Turning the turret toward the target
2.
Finds the vector representing the direction from the tank's turret to the target
that the tank needs to hit, which is
TurretToTarget
.
Normalizes the
ForwardXZPlane
and
TurretToTarget
vectors so that the
length of the vectors is 1.
3.
Finds the angle Theta between the
ForwardXZPlane
and
TurretToTarget
vectors.
4.
5.
Creates a new Orientation class object that is the same as the orientation of
the tank's turret but turned by a small angle PI/16, which is NewO.
6.
Finds the forward vector of this new tank turret orientation, which is
NewForwardXZ
, and then normalizes it.
Finds the angle Theta2 between the
NewForwardXZ
and the
TurretToTarget
vectors.
7.
8.
If the tank weapon is not firing and the tank turret is directly facing the target
plus or minus the
m_TargetAngleTolerance
value, set the tank weapon to fire
and set the
m_StartTimeFiring
variable to the current time.
9.
If Theta2 is greater than Theta, turn the tank turret to the right.
10.
If Theta2 is less than Theta, turn the tank turret to the left.