So, you've created a car prefab using WheelCollider components, and now you can apply a motorTorque to make the whole thing move along.
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.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOFH20NkhRWXiLg21sMCszUaxMUKDDBRxL7rNRvzOL0qDNemKW5tFR9KwjmIzjdqMofLKqKGylL1VTjmUFHBl18eBE9JGeIdhHDlB61BpulCq5T-s3yg3pYJdt0kBcFoPVNuRZWSRSdW8/s200/torque.jpg)
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.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRC74WMYa6d7ParwYoNfHrwTZPgOkKkNEvna-GD17iPvDooZb6oLuXDAZSWbw77drQIir0f7NebAz7LDZVT9UG_TXG2ae-exeBnlUy53gd7PyoEPj5TORRdLNAeJxI4qjW70MmoL8aRQs/s200/gears.jpg)
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!