Game Development Reference
In-Depth Information
The ProcessSteering() function (see Listing 8-59) processes the tank's steering input values.
The function does the following:
Processes the horizontal or left/right steering by calling the TurnTank() to
actually turn the tank's main body
1.
2.
Processes the tank's acceleration by setting the maximum speed allowed
that is associated with the tank's steering input and applying a translation
force to the tank's main body
3.
Processes the tank's deceleration by calculating a slower speed and setting
the maximum speed of the tank to this new slower speed
Listing 8-59. Processing the Tank's Steering
void ProcessSteering()
{
Steering DriverSteering = m_Driver.GetAISteering();
HorizontalSteeringValues HorizontalTurn = DriverSteering.GetHorizontalSteering();
SpeedSteeringValues Acceleration = DriverSteering.GetSpeedSteering();
float TurnDelta = DriverSteering.GetTurnDelta();
float MaxSpeed = DriverSteering.GetMaxSpeed();
float MinSpeed = DriverSteering.GetMinSpeed();
float SpeedDelta = DriverSteering.GetSpeedDelta();
// Process Tank Steering
// Process Right/Left Turn
if (HorizontalTurn == HorizontalSteeringValues.Left)
{
TurnTank(TurnDelta);
}
else if (HorizontalTurn == HorizontalSteeringValues.Right)
{
TurnTank(-TurnDelta);
}
// Process Acceleration
if (Acceleration == SpeedSteeringValues.Accelerate)
{
m_MainBody.GetObjectPhysics().SetMaxSpeed(MaxSpeed);
Vector3 Force = new Vector3(0,0,30.0f);
m_MainBody.GetObjectPhysics().ApplyTranslationalForce(Force);
}
else
if (Acceleration == SpeedSteeringValues.Deccelerate)
{
float Speed = m_MainBody.GetObjectPhysics().GetVelocity().Length();
if (Speed > MinSpeed)
 
Search WWH ::




Custom Search