But how do you calculate vehicles for the motorTorque which make the vehicle reflect reality?
Here are my current ideas on the best way to do this.
1. Create a "torque curve" for your engine. It should run from 0 - 7000 (which reflects your engine RPM) and the height should peak at the maximum power output (in Newton Metres) of the engine. . The below image shows a torque curve which peaks at around 450 newton metres and then sharply drops off near 6000 rpm, just like a real engine. Use an AnimationCurve for this.
2. Set up your masses. The car should weigh between 1000-3000 kg. Set this in the mass property of your rigidbody component. It is also very important to set the mass of your wheels (WheelCollider.mass) to something reasonable. Most car wheels weigh between 15-30 kilograms.
3. Create another AnimationCurve variable, which we will use for gear ratios. Gear 0 should be neutral, and gear -1 should be negative to enable a reverse gear. A typical(?) set of gear ratios are below. Add another float variable which is the "final drive ratio" and set it somewhere between 3 and 4.
4. Every frame, you need to calculate the RPM of the motor. To do this use this formula:
motorRPM = minRPM + (wheelRPM * finalDriveRatio * gearRatios.Evaluate(gearIndex));
minRPM is usually set to 700-1000, depending on the idle RPM of the engine. You can get wheelRPM from your WheelCollider components.
5. Finally, calculate the motorTorque.
totalMotorTorque = torqueCurve.Evaluate(motorRPM) * gearRatios.Evaluate(gearIndex) * finalDriveRatio * accel;
If you have four drive wheels, set each wheel's motorTorque to totalMotorTorque / 4. If you have only two drive wheels (front or rear wheel drive), set each wheels motorTorque to totalMotorTorque / 2. accel is a float variable which specifies how far the accelerator cable is depressed, and should be between 0 and 1.
6. Fill in the gaps. You need to add a mechanism to change the gearIndex value (which specifies which gear the car is in) and a mechanism to modify the accel value.
7. Tweak the curves. Just like a real car, minor adjustments to weight, torque curves or gear ratios can have a dramatic impact on the car's performance. Don't be surprised if you get crazy behavior from seemingly minor modifications!