Game Development Reference
In-Depth Information
m_WeaponType = GetParent().GetCurrentOrder().GetObjectsAffected();
m_RoundsToFire = GetParent().GetCurrentOrder().GetDeltaAmount();
m_TimeIntervalBetweenFiring = (long)GetParent().GetCurrentOrder().GetDeltaIncrement();
// Tell the Pilot class what command is actually being executed in the FSM
GetParent().SetCommandExecuting(AIVehicleCommand.Patrol);
}
The Exit() function is called before this state is exited by the finite state machine. This function
increments the current waypoint to the next waypoint, indicating that the current waypoint has been
reached and the tank needs to move to the next waypoint in the list. (See Listing 8-31.)
Listing 8-31. Exiting the State
void Exit()
{
// Update Current Waypoint to next WayPoint
GetParent().IncrementNextWayPoint();
}
The TurnTurretTowardTarget() function determines the horizontal or left/right steering direction
of the tank's turret, so that the tank's weapon turns to face the target. (See Listing 8-32 for the full
source code.)
Listing 8-32. Turning the Tank Turret Toward the Target
void TurnTurretTowardTarget(Vector3 Target)
{
// 1. Find vector from front of vehicle to target
Vector3 ForwardXZPlane = new Vector3(0,0,0);
ForwardXZPlane.x = GetParent().GetAIVehicle().GetTurret().m_Orientation.
GetForwardWorldCoords().x;
ForwardXZPlane.z = GetParent().GetAIVehicle().GetTurret().m_Orientation.
GetForwardWorldCoords().z;
Vector3 TurretPosition = new Vector3(0,0,0);
TurretPosition.x = GetParent().GetAIVehicle().GetTurret().m_Orientation.GetPosition().x;
TurretPosition.z = GetParent().GetAIVehicle().GetTurret().m_Orientation.GetPosition().z;
Vector3 WayPointXZPlane = new Vector3(Target.x, 0, Target.z);
Vector3 TurretToTarget = Vector3.Subtract(WayPointXZPlane, TurretPosition);
// 2. Normalize Vectors for Dot Product operation
ForwardXZPlane.Normalize();
TurretToTarget.Normalize();
// P.Q = P*Q*cos(theta)
// P.Q/P*Q = cos(theta)
// acos(P.Q/P*Q) = theta;
 
Search WWH ::




Custom Search