Custom Vehicle Controller
  • Custom Vehicle Controller
  • Guides
    • Workflow
      • Quick Setup
      • Creating New Parts
      • Modifying Parts
      • Creating Vehicle Parts Presets
      • Customizable Sets and Runtime Parts Change
      • Engine Performance Customization
      • Exposing Current Car Stats
    • API
      • CustomVehicleController
      • VehicleEngineSoundManager
      • RaceManager
      • RacerProgress
      • RaceSpawner
      • CollisionHandler
    • Vehicle Controller Input Provider
      • Input System Example
      • Mobile Input
    • Tips, Warnings and Requiremens
      • Work With Editor
      • Vehicle Set Up
    • AI Setup
      • AI Racer Creation
      • AI Racer Setup
      • AI Chaser Setup
      • Race Creation
      • Race Configuration
      • Race Information
    • Vehicle Damage System
      • Vehicle Damage Controller
      • Collision Area Partitioner
      • Part Damage Handler
      • Vehicle Attachments Aligner
      • Collision Handler
    • Additional Settings
      • Custom Vehicle Controller
      • Car Visuals Essentials
    • Package Settings
      • Assets Save Location
      • Project-Wide Surface Settings
    • Extra
      • Adding Visual Effects
        • Individual Effect Set Up
      • Adding Sound Effects
        • Adding Engine Sound
        • Adding Extra Sound Effects
  • Converting To Other Render Pipelines
    • Convert To Built-in RenderPipeline
    • Convert To HDRP RenderPipeline
Powered by GitBook
On this page
  • Quick Setup Guide:
  • Full Setup Guide:
  • 1. Setting up the controller
  • 2. Assign vehicle parts set
  • 3. Player input
  1. Guides
  2. Workflow

Quick Setup

Learn how to set up the vehicle controller

PreviousWorkflowNextCreating New Parts

Last updated 1 year ago

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:

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.

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.

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.

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.

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

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:

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.

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.

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.