Creating a car

From UnityCar Wiki

Jump to: navigation, search

Contents


Creating a car from scratch

Click on "UnityCar" menu voice under "GameObject/Create Other/" menu.

Keep in mind that the layer of the car GameObject and the layer of the ground GameObject must be different (Layers documentation). UnityCar uses a layermask on the car's GameObject layer, so casting functions will ignore colliders with the same layer the car GameObject. So If car GameObject layer and ground GameObject layer are the same, castings will ignore ground colliders and the car will sink into the ground.

Creating a car01.jpg


Once you clicked on UnityCar menu voice, a new complete and fully functional car is created automatically:

Creating a car02.jpg


Now replace present meshes with your meshes in Body and Wheels GameObjects:

Creating a car03.jpg


Now put the wheel mesh GameObject in the Model parameter of the respective Wheel.cs (its used to rotate the wheel mesh) and move Wheel.cs GameObject (NOT wheel mesh gameObject, which must be at (0,0,0) position and (0,0,0) rotation) so that the wheel stays at the center of the wheelhouse and in the maximum suspension compression position. Be sure that the center point and the pivot point of the wheel mesh coincides, otherwise wheel will not rotate around its actual center. Optionally put the caliper mesh GameObject in the Caliper Model parameter.

Creating a car04.jpg


Optionally, you can replace the standard Box Colliders with a more precise Mesh Collider .

To create a Mesh Collider , select car body mesh GameObject, add a Mesh Collider component (Component/Physic/MeshCollider) and check the Convex checkbox.

If the resulting mesh collider has more than 255 polygons , Unity will give an error ("The hull has more than 255 polygons. This is invalid").

In this case you have to create the mesh collider with an external program, like 3D Studio or MeshLab (http://meshlab.sourceforge.net/).

Remember to check the Convex checkbox of the Mesh Collider. Mesh Collider is needed to use the damages features of UnityCar:

Creating a car05.jpg



Creating a car using an existing model

Select the root of your car's GameObject and add the following scripts from UnityCarScript Folder:

1. Axles.cs

2. DriveTrain.cs

3. AxisController.cs or MouseController.cs or MobileController.cs, depending on what you need (you can also add all of them).

4. CarDynamics.cs

Select each of the wheels GameObject and add Wheel.cs class.

For each of the wheels put the wheel mesh GameObject in the Model parameter of the respective Wheel.cs. Optionally put the caliper mesh GameObject in the Caliper Model parameter:

Creating a car06.jpg


Now select each wheel GameObject and put it in the right parameter of Axles.cs (front left wheel in the left wheel of front axle, front right wheel in the right wheel of front axle etc.):

Creating a car07.jpg


Keep in mind that the layer of the car GameObject and the layer of the ground GameObject must be different (Layers documentation). UnityCar uses a layermask on the car's GameObject layer, so casting functions will ignore colliders with the same layer the car GameObject. So, If car GameObject layer and ground GameObject layer are the same, castings will ignore ground colliders and the car will sink into the ground.

The above classes are the only classes needed on order to create a full working car. The other classes (CarDamage.cs, SoundController.cs etc.) are optional.

Personal tools
Car Tuning
Track Tutorials
Configuration