Try importing the attached package into a new, empty Unity session (I used 2020.3.3, but anything reasonably up-to-date should be OK). I have not attempted to make the code elegant, versatile or easy to maintain, but hopefully it is easy to follow…
This demonstrates a car accelerating from stationary to 25 m/s and then braking to 20 m/s in the next 50 m. Here are some random notes/observations that you might find useful.
The biggest problem you are likely to face is wheel slip. You will see I have added a very basic data log of what is happening to the car and there is a small amount of slip occurring at the start. In an effort to keep the code simple I have not corrected for this and you will see the car only reached 24 m/s instead of the target of 25 m/s. This could be resolved by applying the motor torque until the correct velocity is reached instead of purely relying on the time.
You need to accelerate the car from stationary as I am not aware of any way to initiate a wheel collider as moving and in stable contact with the ground (wheel collider RPM is readonly - EDIT: I believe this had changed as of late 2022). You cannot just set the velocity of the car rigidbody as this will result in a large amount of noise and slip as the tyre tries to match ground speed.
Another reason for instability at the start can be the suspension forces balancing out which can result in transient reductions in the contact force; these in turn allow slip to start. Try to ensure you don’t see your car drop down / spring up in the first second of the simulation. Or just allow your car a couple of seconds to settle before you apply any torques to the wheels.
The SubSteps class is to enable substeps in the physics engine for the wheel colliders. I believe it only needs to be added for a single collider to enable it for all colliders, but I have not tested this and just pasted the code in. This really helps to stabilize the wheel contact with the ground.
Acceleration and braking would be smoother if the torques were ramped (lerped) in rather than stepped, this would reduce wheel slip (obviously, you would need to allow for this separately in your calculations).
I’ve supplied a couple of functions based on the equations of motion that I linked to earlier, hopefully you can see enough here to figure out any others you may need.
You may want to check out Vehicle Physics Pro - Community Edition | Physics | Unity Asset Store for a complete and free vehicle model (note, I have no affiliation with this and have not used it, but it comes very highly rated).
I hope some of that helps.
7101751–846514–cartest.unitypackage (8.6 KB)