Help needed for implementing clutch - Printable Version

+- Forums (
+-- Forum: Project (
+--- Forum: Development (
+--- Thread: Help needed for implementing clutch (/showthread.php?tid=1308)

Help needed for implementing clutch - NewLife - 07-03-2010

Hi all,
Im michele from italy and Im developing a racing simulation web oriented, and i would like to ask you help cause im experiencing some problems in implementing the clutch.
First of all i have to thank you all cause your forum is a invaluable source for a developer.
now my help request:
Im having serious difficulties in developing the clutch, i cant make it work like i would.
im modelling the clutch like a viscous coupling, "stealing" the idea from vdrift.

the code is:

float averageWheelsAngularVelo = 0;
foreach(Wheel w in poweredWheels)
  averageWheelsAngularVelo += w.angularVelocity * drivetrainFraction;
ClutchSpeed=averageWheelsAngularVelo* ratio; // wheels average speed *ratio
ClutchTorque = clutch.GetTorque(engineAngularVelo, ClutchSpeed,engineTotalTorqueMax);

engineTorque = CalcEngineTorque(rpm) * throttle;

if (clutch.IsLocked())

engineTotalTorque = engineTorque - engineFrictionTorque - ClutchTorque;

// update engine angular velo
engineAngularVelo  += (engineTotalTorque) / engineInertia * Time.deltaTime;

if (ratio != 0 && clutch.GetClutchPosition()!=0)   //clutch engaged or engaging

    // Apply torque to wheels
    foreach(Wheel w in poweredWheels)
        lockingTorque = (averageWheelsAngularVelo - w.angularVelocity) * differentialLockCoefficient;
        w.drivetrainInertia = inertia * drivetrainFraction;
        w.driveFrictionTorque = engineFrictionTorque * Mathf.Abs(ratio) * drivetrainFraction;
        w.driveTorque =  TransferedTorque * ratio * drivetrainFraction + lockingTorque;
        slipRatio += w.slipRatio * drivetrainFraction;

the GetTorque function is:

// clutch is modeled as limited highly viscous coupling
public float GetTorque ( float n_engine_speed, float n_clutch_speed, float engine_max_torque)
    engine_speed = n_engine_speed;
    clutch_speed = n_clutch_speed;
    new_speed_diff = engine_speed  - clutch_speed;
    locked = true;
    if (clutch_position ==0) {
        locked = false;
        return 0;
        max_torque = clutch_position * torque_capacity;
        friction_torque = max_torque* (new_speed_diff/factor);    // viscous coupling (locked clutch)

        if (friction_torque > max_torque) // slipping clutch
            friction_torque  = max_torque;
            locked = false;
        else if (friction_torque < -max_torque) // slipping clutch
            friction_torque  = -max_torque;
            locked = false;

        //friction_torque =Mathf.Min(engine_max_torque,friction_torque);
        last_torque = friction_torque;
        return friction_torque;

as you can see Im using a "factor" to decrease the speed_diff between engine and the clutch (new_speed_diff/factor), cause without that clutch is always slipping (new_speed_diff is always >1). the problem is that this is a patch, and i have to find the right factor for every car and engine i put in my sim.
Probably i need a function that update the engineangularvelo while engaging, but i really dont know if this is the right way and how to implement it.
Can someone help me please??

PS: if someone is interested this is the link of a demo of my sim:

you can play it directly online, you dont have to donwload and install anything, excpet for the unity3d plugin, a plugin like flash but optimized for 3d graphics.ù

thank you all


- NaN - 07-03-2010

Yeah, this clutch model hasn't worked that well in vdrift too. You might want to take a look at: