Game Development Reference
In-Depth Information
The FireTurretWeapon() function fires the tank's primary or secondary weapon, depending on the
AIVehicleObjectsAffected value. If the weapon is successfully fired, then the m_NumberRoundsFired
variable is incremented by 1. (See Listing 8-33.)
Listing 8-33. Firing the Tank's Turret Weapon
void FireTurretWeapon()
{
Vector3 Direction = GetParent().GetAIVehicle().GetTurret().m_Orientation.
GetForwardWorldCoords();
boolean IsFired = false;
if (m_WeaponType == AIVehicleObjectsAffected.PrimaryWeapon)
{
IsFired = GetParent().GetAIVehicle().FireWeapon(0, Direction);
}
else
if (m_WeaponType == AIVehicleObjectsAffected.SecondaryWeapon)
{
IsFired = GetParent().GetAIVehicle().FireWeapon(1, Direction);
}
if (IsFired)
{
m_NumberRoundsFired++;
}
}
The SteerVehicleToWayPointHorizontal() function steers the main tank body left or right toward the
waypoint. (See Listing 8-34 for the full source code.)
Listing 8-34. Steering the Vehicle to the Current Waypoint
void SteerVehicleToWayPointHorizontal(Vector3 WayPoint)
{
// 1. Find vector from front of vehicle to target
Vector3 ForwardXZPlane = new Vector3(0,0,0);
ForwardXZPlane.x = GetParent().GetAIVehicle().GetMainBody().m_Orientation.
GetForwardWorldCoords().x;
ForwardXZPlane.z = GetParent().GetAIVehicle().GetMainBody().m_Orientation.
GetForwardWorldCoords().z;
Vector3 VehiclePosition = new Vector3(0,0,0);
VehiclePosition.x = GetParent().GetAIVehicle().GetMainBody().m_Orientation.GetPosition().x;
VehiclePosition.z = GetParent().GetAIVehicle().GetMainBody().m_Orientation.GetPosition().z;
Vector3 WayPointXZPlane = new Vector3(WayPoint.x, 0, WayPoint.z);
Vector3 VehicleToWayPoint = Vector3.Subtract(WayPointXZPlane, VehiclePosition);
// 2. Normalize Vectors for Dot Product operation
ForwardXZPlane.Normalize();
VehicleToWayPoint.Normalize();
 
Search WWH ::




Custom Search