Game Development Reference
In-Depth Information
Listing 8-47. Setting a New Order for the Tank
void SetOrder(VehicleCommand Command)
{
m_LastOrder = m_CurrentOrder;
m_CurrentOrder = Command;
if (m_CurrentOrder.GetCommand() == AIVehicleCommand.Patrol)
{
// Set Inital WayPoint
Vector3[] WayPoints = m_CurrentOrder.GetWayPoints();
m_WayPoint = WayPoints[0];
}
}
The Update() function clears the steering input for the tank and updates the finite state machine that
controls the tank. (See Listing 8-48.)
Listing 8-48. Updating the Driver
void Update()
{
// Clear AISteering
m_AISteer.ClearSteering();
// Update FSM Machine
m_FiniteStateMachine.UpdateMachine();
}
Modifying the Physics Class
The Physics class has to be modified to support our new tank vehicle.
The UpdatePhysicsObjectHeading() function must be added into the Physics class (see Listing 8-49).
The UpdatePhysicsObjectHeading() function does the following:
1.
Applies gravity to the object, if gravity is on.
2.
Updates the linear velocity of the object.
3.
Updates the angular velocity of the object.
4.
Resets the forces acting on the object to 0 by setting the linear and angular
acceleration to 0.
5.
Adjusts the velocity so that all the object's speed is redirected along the
Heading. If the speed of the object is greater than m_MaxSpeed , set the speed
to m_MaxSpeed . If gravity is on, use the y component of the velocity from step
1 in the calculation of the object's new velocity.
6.
Updates the object's linear position, taking into account the gravity and
ground floor settings in adjusting the object's vertical position.
7.
Updates the object's angular position.
 
Search WWH ::




Custom Search