Realistically drivable car

I want my car to be realistically drivable (like in real life...)

Unfortunately all I did so far is Rotate the whole vehicle using A and D; and AddForce in forward-backward direction using W and S (which didn't prevent it from moving sideways and yes, I am using Rigidbody)

I'm assuming I'd have to let front wheels rotate independently from the rest of the car, but how do I use them to move the car? And how do I force the car to move only in the direction of the wheels while still making drifting at high speeds possible?

You probably don't want to use AddForce, and definitely don't use Rotate for physics since it completely overrides the physics engine (and collisions).

Use WheelColliders. They're specifically made for this purpose. I've used AddForce in conjunction with WheelColliders with extremely low friction to simulate arcade style hovering vehicles, but anything remotely realistic is going to need a lot more than that. WheelColliders expose properties that handle the suspension, tires, braking, acceleration and steering. Unity's implementation isn't perfect, but if you make sure that you're using the correct scale for your objects, with a few tweaks it can be used for a rather realistic setup.

This tutorial, by the creator of one of the biggest 3rd party vehicle plugins for Unity goes over a few tips you can use to get the most out of WheelColliders. To sum it up, it's goes over using the right units, "fudging" the center of gravity to help with roll, and most importantly, how to simulate an anti-roll bar (it's very easy to underestimate how incredibly important an anti-roll bar is in keeping a vehicle upright, and this carries over to Unity as well)

Using the physics engine joints for the suspension won't be particularly worth the trouble. Instead use the WheelCollider suspension in conjunction with procedural animation to get the best blend of realistic behavior, and a robust implementation.

WheelColliders are an extremely well explored area in Unity so do some searching in addition to looking at that tutorial, you'll find various implementations of features like gearboxes and simulated drivetrains. WheelColliders are really a good base that you can build on. Even more advanced realism features such as tire wear and temperature can all be simulated if you're willing to experiment with the various parameters they expose.

If you want realism, follow the physics of a real car. 4 tires on the ground. Only front two can rotate.

For front wheel drive, on each of the two front wheels, I believe rigidbody.addTorque(Vector3) is what you are looking for.

But there is a lot more to it. And I am not a mechanical engineer, so you may need an expert in the field to know where the vehicle weight needs to be and such. Tread on the tires help keep it sticking to the ground, but you can probably just mess with friction or something there.

• ok, so 4 rotating wheels. but how would I connect the car to them, if they are rotating? – zoran404 Feb 14 '15 at 18:07
• 2 rotating wheels, unless you have AWD or 4WD. And I think a configurable joint would be the best choice – Evorlor Feb 14 '15 at 18:08
• I'm assuming 3d. 2d would be much easier. – Evorlor Feb 14 '15 at 18:09
• 3d yes. And I'll try adding the joints for all 4 wheels, to avoid drag. thanks – zoran404 Feb 14 '15 at 18:12
• I was typing a comment here but I made it into an answer, directly manipulating the Rigidbody with AddForce and AddTorque isn't going to lend itself to a realistic simulation since they affect the entire vehicle as a solid mass. Use WheelColliders instead. Even if you're not that focused on realism, I'd say WheelColliders provide more robust setup than adding forces to the rigidbody. – Selali Adobor Feb 15 '15 at 1:34