Quick Setup
Learn how to set up the vehicle controller
Last updated
Learn how to set up the vehicle controller
Last updated
An editor window should open:
For ease of use, you can dock the editor window.
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.
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.
You can lock the window by checking the toggle at the bottom of the editor:
Wheel models must have a standard Unity orientation (Y - up, Z - forward, X - right)
Wheel objects must have the origin in the center of the mesh for correct rotation. Alternatively, you can parent each wheel to an empty GameObject, setting the wheel's local position correctly and then assign the parent gameobjects to the editor object fields. Note, however, that in this case you would have to set the wheel radius manually
Setting vehicle body MeshRenderer is optional, but it allows the editor to automatically calculate the center of mass of the vehicle.
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.
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.
To find out how to manually set up the controller go here.
If the selected game object is a prefab, you'll need to unpack it. If you try to initialize the controller on the prefab, a warning will be shown:
After clicking "Yes", the prefab will be unpacked completely and the controller will be initialized. You won't be able to initialize the controller as long as the selected game object is a prefab.
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.
If you want to make the vehicle drive at high speed ( ≈ > 50 m/s), some changes to rigidbody settings must be made
CustomVehicleController asset uses ScriptableObjects to represent the following vehicle parts:
Engine
Nitrous (optional)
Forced Induction (optional, part of the engine)
Transmission
Tires
Suspension
Brakes
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:
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.
In the editor window you can create and edit new parts and presets of vehicle parts.
For the vehicle parts preset creation guide go here.
For the vehicle parts creation guide go here.
For the vehicle parts guide go here.
At this point, the vehicle should be set up completely. All that's left is input handling.
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.
CustomVehicleController expects a component that extends IVehicleControllerInputProvider. For more info, go here.
Do not forget to add colliders to the vehicle if you haven't already.
If you use multiple colliders or a mesh colliders, additional set up is required. Read more here
You should have a car that drives.