Quick Setup

Learn how to set up the vehicle controller

Quick Setup Guide:

Full Setup Guide:


1. Setting up the controller

1. Open the editor window by going to Tools -> Custom Vehicle Controller -> Vehicle Editor.

An editor window should open:

circle-info

For ease of use, you can dock the editor window.

1.1 Drag a vehicle model into the scene.

1.2. Select a root game object of your vehicle with the CustomVehicleController script attached.

circle-info

If the selected game object doesn't have a CustomVehicleController component already, you can add it from the editor window.

You can also add the BoxCollider component to the selected game object if you wish so by checking the toggle. The selected game object should have the vehicle body mesh, otherwise the BoxCollider component won't be scaled automatically to match the model size.

1.3 Drag and drop references to the wheels and vehicle body MeshRenderers.

circle-info

Version 1.1.0 added support for children game objects of the wheel that must follow it's position and ignore rotation around the X axis. Group up such elements (like brakes) under parent game objects and assign them (optionally) to the Transform field near each wheel when initializing the controller.

circle-info

You can lock the window by checking the toggle at the bottom of the editor:

circle-exclamation
circle-exclamation
circle-info

Setting vehicle body MeshRenderer is optional, but it allows the editor to automatically calculate the center of mass of the vehicle.

circle-info

Ideally, the wheel transforms you provide should have the MeshRenderer component that has the wheel model. It allows for automatic calculation of wheel radius and the position of suspension.

1.4 Initialize the controller.

After clicking the "Initialize Controller" button, the hierarchy of game objects will be created, necessary scripts for the wheel physics added, script references populated, and, in case the wheel transform references have a MeshRenderer component, suspension position and wheel radius will be calculated.

circle-info

To find out how to manually set up the controller go here.

triangle-exclamation

Now, the hierarchy should look like this:

The selected game object should have:

CustomVehicleController component - manages the vehicle behavior

CarVisualsEssentials component - manages wheels` rotation and position

Rigidbody

with references to newly created scripts and the center of mass assigned.

circle-exclamation

2. Assign vehicle parts set

CustomVehicleController asset uses ScriptableObjects to represent the following vehicle parts:

  1. Engine

  2. Nitrous (optional)

  3. Forced Induction (optional, part of the engine)

  4. Transmission

  5. Tires

  6. Suspension

  7. Brakes

  8. Body

CustomVehicleController component expects either a VehiclePartsPresetSO, which is a scriptable object that holds references to the used vehicle parts:

Or individually set up vehicle parts:

circle-info

Using a preset means that any modifications to it will affect every preset user. For this reason, a customizable set exists. Learn how to update parts at runtime here.

With the vehicle initialized and the vehicle game object selected, open the editor window.

Make sure the "Use Presets On This Controller" toggle is turned on:

In the Preset Settings foldout, select any VehiclePartsPresetSO instance.

circle-info

In the editor window you can create and edit new parts and presets of vehicle parts.

circle-info

For the vehicle parts preset creation guide go here.

circle-info

For the vehicle parts creation guide go here.

circle-info

For the vehicle parts guide go here.

At this point, the vehicle should be set up completely. All that's left is input handling.

3. Player input

For handling player input, you are provided a script that uses old Unity's input system. Add it to the GameObject with the CustomVehicleController component.

circle-info

CustomVehicleController expects a component that extends IVehicleControllerInputProvider. For more info, go here.

circle-exclamation

You should have a car that drives.

Last updated