Game Development Community

T3D 1.1 Beta 1 - WheeledVehicle does not properly take brake slowdown into consideration - LOGGED

by Dave Calabrese · in Torque 3D Professional · 08/10/2010 (6:34 pm) · 1 replies

The braking system for T3D currently uses the following equation to initiate braking:

engineTorque = 0;

The result of this is if the player taps on the brake, the car will slam to a halt. This is not realistic, and I doubt it's the desired action.

The following code change will add in the ability to have a brake value that can be defined on a per-vehicle basis, and will allow proper slowdown of the vehicle. We do this against the engineTorque itself and inside the WheeledVehicle class to allow a full and proper slowdown, rather than just flat out cutting the movement torque.

wheeledVehicle.cpp
Around line 208:
brakeStrength = 1;

Around line 353:
addField("brakeStrength", TypeF32, Offset(brakeStrength, WheeledVehicleData));

Around line 757, change the code to read:
F32 engineTorque = 0;
   F32 brakeVel = 0;
   if (mBraking) 
   {
      brakeVel = (mDataBlock->brakeTorque / aMomentum) * dt;
      engineTorque -= mDataBlock->brakeStrength;
	  if(engineTorque < 0.0)
		  engineTorque = 0;
   }

In wheeledVehicle.h
Around line 109
F32 brakeStrength;		// Amount to subtract from the current torque while the vehicle is braking

Then in the WheeledVehicleData datablock on the script level, be sure to add a braking value, such as:
brakeStrength = 0.01;      // Amount of strength subtracted from the active engineTorque while braking.

Also, since I am working with an actual set of gas / brake game controller pedals, I've updated the gamepadPitch script function to work better with the system. (However, there should probably be a separate script level control path for steering wheel control input so we are not using the gamepad function.)

Therefore, the updated 'Pitch' script command should actually be the following:
function driveControllerPedals(%val)
{
   // Negative is Gas. Positive is Brakes   
   if(%val > 0)
   {
      // Brakes
      $carIsGassing = false;
      $mvForwardAction = 0;
      $mvTriggerCount2 = 1;
   }
   else if(%val < 0)
   {
      // Gas
       $mvTriggerCount2 = 0;
       isGassing(0);
   }
   else
   {
      $carIsGassing = false;
      $mvTriggerCount2 = 0;
      $mvForwardAction = 0;
   }
}

function isGassing(%val)
{
   if($carIsGassing && %val || !$carIsGassing && !%val)
   {
      $carIsGassing = true;
      $mvTriggerCount2 = 0;
      $mvForwardAction += 0.05;
      
      schedule(2,0,isGassing,1);
   }
}