Manual transmission example?

Hiya. I’m looking for some pointers on how to go about coding a manual transmission for a vehicle in javascript. I’ve found 2 examples so far in the car.js script from the networking example and in jcar.cs but I’m finding it difficult to extract just the parts of those scripts that are specific to the function of the transmission and the subsequent locomotion of the vehicle.

The idea behind the transmission is that the engine has a powerband that exists within a certain RPM range (eg. 5000 - 6000 RPM). So you need to shift the engine to keep the RPM’s within/near that range for optimum horsepower. And if you don’t shift, you could over-rev the engine.

  • Ideally the transmission would have 4 - 5 forward gears with specific ratios for each one. The player would press up/down buttons to shift gears.

  • The rear axle would also have it’s own gear ratio (final drive).

  • The engine might need to have a specific set max horsepower for the ideal RPM range. I’m not sure how that would factor in.

  • The script would somehow take the RPM (or the resulting force taken after the real axle ratio?) and convert it to an appropriate number that can be plugged into something like Rigidbody.AddRelativeForce (0, force, 0) to move the car forward.

  • My vehicle is very simple and does not have wheels (think Super Sprint).

Some pseudo-code:

v is the car’s velocity in meters/second.
r is the wheel radius in meters.

Then you have:

wheelRPM = v * 60 / (r * 2 * pi);
engineRPM = wheelRPM * finalDriveRatio * gearRatio;

Then you can calculate the engine torque from the engine RPM using some torque curve. Google to find torque curves for typical cars - then just find some function to match a torque curve for the desired power band:

engineTorque = TorqueFunction(engineRPM);

wheelTorque = engineTorque / (finalDriveRatio * gearRatio);
wheelForce = wheelTorque / r;

1 Like

http://www.gotow.net/andrew/wordpress/?page_id=78