Game Development Community

Better vehicle control.

by David Byrge · in Torque Game Engine · 04/09/2007 (8:53 pm) · 4 replies

Is making the vehicle having better control mainly engine or script based? I have seen some resources regarding some code mods but they seem a little outdated for 1.5.1 tge. Has anyone had any luck with realistic driving/physics?

#1
04/09/2007 (8:59 pm)
A lot can be done via script.

Here's some typical settings that I use for a more realistic (yet fun to drive) vehicle:
// 3rd person camera settings
   cameraRoll               = true;        // Roll the camera with the vehicle
   cameraMaxDist            = 8;           // Far distance from vehicle
   cameraOffset             = 1.5;         // Vertical offset from camera mount point
   cameraLag                = 0.1;         // Velocity lag of camera
   cameraDecay              = 0.75;        // Decay per sec. rate of velocity lag

   // Rigid Body
   mass                     = 400;
   massCenter               = "0 -0.5 0";  // Center of mass for rigid body
   massBox                  = "0 0 0";     // Size of box used for moment of inertia,
                                           // if zero it defaults to object bounding box
   drag                     = 0.6;
   bodyFriction             = 0.6;
   bodyRestitution          = 0.4;
   minImpactSpeed           = 5;           // Impacts over this invoke the script callback
   softImpactSpeed          = 5;           // Play SoftImpact Sound
   hardImpactSpeed          = 15;          // Play HardImpact Sound
   integration              = 4;           // Physics integration: TickSec/Rate
   collisionTol             = 0.1;         // Collision distance tolerance
   contactTol               = 0.1;         // Contact velocity tolerance

   // Engine
   engineTorque             = 5000;        // Engine power
   engineBrake              = 1000;        // Braking when throttle is 0
   brakeTorque              = 10000;       // When brakes are applied
   maxWheelSpeed            = 17.5;        // Engine scale by current speed / max speed

The only source code changed I've made was to fix the handbrake (moved it to a different trigger) and auto center the two front wheels after steering is released.
#2
04/09/2007 (9:18 pm)
Ok, thank you very much for the quick response and help. I made the changes and I like it a whole lot better. The one thing that I still don't like is the sensitivity of the steering. It feels like I am driving a boat instead of a car. Where is the section to change the sensitvity of the steering?
#3
04/09/2007 (9:34 pm)
Replace the contents of your tire and spring datablocks with these (change the datablock names and dts path etc to match yours):
datablock WheeledVehicleTire(carTire)
{
   // Tires act as springs and generate lateral and longitudinal
   // forces to move the vehicle. These distortion/spring forces
   // are what convert wheel angular velocity into forces that
   // act on the rigid body.
   shapeFile              = "~/data/shapes/car/car_tire.dts";
   staticFriction         = 4;
   kineticFriction        = 1.25;
   
   // Spring that generates lateral tire forces
   lateralForce           = 6000;
   lateralDamping         = 400;
   lateralRelaxation      = 1;
   
   // Spring that generates longitudinal tire forces
   longitudinalForce      = 6000;
   longitudinalDamping    = 400;
   longitudinalRelaxation = 1;
};

datablock WheeledVehicleSpring(carSpring)
{
   // Wheel suspension properties
   length        = 0.25; // Suspension travel
   force         = 3000; // Spring force
   damping       = 1200; // Spring damping
   antiSwayForce = 5;    // Lateral anti-sway force
};

And the onAdd function to this:
function WheeledVehicleData::onAdd(%this,%obj)
{
   // Setup the car with some defaults tires & springs
   for (%i = %obj.getWheelCount() - 1; %i >= 0; %i--) {
      %obj.setWheelTire(%i,carTire);
      %obj.setWheelSpring(%i,carSpring);
      %obj.setWheelPowered(%i,false);
   }
   
   // Steer front tires
   %obj.setWheelSteering(0,1);
   %obj.setWheelSteering(1,1);

   // power all 4 wheels...
   %obj.setWheelPowered(0,true); // front left
   %obj.setWheelPowered(1,true); // front right
   %obj.setWheelPowered(2,true); // rear left
   %obj.setWheelPowered(3,true); // rear right

   %obj.setRechargeRate(%this.rechargeRate);
   %obj.setEnergyLevel(%this.MaxEnergy);
   %obj.setRepairRate(0);
   %obj.mountable = true;
}

For greatly improved steering, open wheeledVehicle.cc and alter the updateMove function to this:
void WheeledVehicle::updateMove(const Move* move)
{
   Parent::updateMove(move);

   // Break on trigger
   mBraking = move->trigger[4];// shift handbrake to trigger 4 so we can still use jump sentinel

   // Set the tail brake light thread direction based on the brake state.
   if (mTailLightThread)
      mShapeInstance->setTimeScale(mTailLightThread,mBraking? 1: -1);

   // Steering return-to-center
	F32 returnSpeed = mFabs( move->y * .04 ); // based on forward/backward motion

	if( mSteering.x > 0 )
	{
		mSteering.x -= returnSpeed;
		if (mSteering.x < 0) mSteering.x = 0;
	}
	else if( mSteering.x < 0 )
	{
		mSteering.x += returnSpeed;
		if (mSteering.x > 0) mSteering.x = 0;
	}

	if( mSteering.y > 0 )
	{
		mSteering.y -= returnSpeed;
		if (mSteering.y < 0) mSteering.y = 0;
	}
	else if( mSteering.y < 0 )
	{
		mSteering.y += returnSpeed;
		if (mSteering.y > 0) mSteering.y = 0;
	}
	// End steering return-to-center code
}
#4
04/10/2007 (5:56 am)
Awesome!!! I will give this a try tonight. Thank you.