Getting started #

Open the example project in Unity 3D (you should have set it up already). Let's play and walk through some example scenes so you could get started quickly. Load and play the scene Playground 1k - JPickup - Keyboard:

Assets > Development > Playground 1k - JPickup - Keyboard

The vehicles in all these scenes typically begin with the engine off. For starting the engine:

  1. Press K for moving the ignition key from "Off" to "Acc-On" (check out the telemetry window)
  2. Press and hold K for moving the ignition key to "Start" and actually start the engine.

    ctrl-K moves the ignition key back to the "Off" switching off the engine.

The scenes containing Steering Wheel in the name require a steering wheel controller. The POV left-right directions act as ignition key. Move to the right once, then move and hold for start the engine.

Keyboard layout:

Key(s) Function Notes
K Ignition key Press to move from "Off" to "Acc-On". Press and Hold for "Start". ctrl+K moves the key back to "Off".
leftright Steering
up Throttle
down Brakes
shift Clutch Actual vehicle setup uses a Torque Converter, which doesn't require active clutch. Still, the clutch can be used to completely disengage the engine from the transmission.
space Handbrake Affects rear wheels. Clutch should be used if vehicle uses a standard clutch to prevent the engine to stall.
ctrl+space Toogle all brakes Brakes are toggled in all wheels.
R Reverse gear If auto-shift is enabled R requires the vehicle to be nearly stopped and brakes released.
N Neutral gear Auto-shift will engage first gear when throttle is applied.
Tab Gear Up Auto-shift might revert to the previous gear
Caps Lock Gear Down Auto-shift might revert to the previous gear
1-5 Engage gear Auto-shift might discard the change and choose a more convenient gear
Page upPage down Gear mode Select the different gear modes if the vehicle has Automatic transmission (M P R N D L). The actual modes may be engaged or not depending on specific conditions (i.e. Reverse requires the vehicle to be nearly stopped).
B Toggle telemetry data
C Change camera
F1-F4 Select different camera modes
Escape Reset scene
T Toggle slow motion mode

Vehicle setup #

The main component that implements the vehicle simulation is VP Vehicle Controller. The object VPP Pickup in the pickup test scene contains this component with all its settings to play with:

VP Vehicle Controller

The mass of the vehicle is configured at the Rigidbody component.

Wheel properties (radius, mass) and suspension settings (spring, damper) are handled per-wheel at the VP Wheel Collider components:

VP Wheel Collider

Other components #

The other components present at the Vehicle gameobject provide different add-on functionalities and features:

VP Vehicle add-on components

VP Standard Input

Reads the user input from the standard Unity Input class, then converts it into input for the vehicle: steering, throttle, brake, etc.

VP Audio

Plays various audio effects based on the state of the vehicle and the wheels.

VP Tire Effects

Triggers the tire-related effects such as marks, trails, smoke, and dust based on the state of each wheel and the underlying Ground Material.

VP Visual Effects

Plays various visual effects such as the steering wheel rotation, brake and reverse lights, and dashboard gauges.

VP Telemetry

Displays a overlay window with detailed numeric data on the wheels and the vehicle. Toggle with the B key.

VP Camera Target Setup

Configures the parameters for this vehicle to be properly looked at with the Camera Controller component, such as minimum distance, view height, and more.

Ground Materials #

The component VP Ground Material Manager manages the ground materials present at the scene.

VP Ground Materials

Each Ground Material defines the material properties such as grip, drag, and the objects used for playing the tire effects (marks, smoke...) on that material.

The ground materials are identified by the Physics Materials assigned to the colliders in the scene. Colliders without Physic Material assigned can also have their Ground Material (Physic Material = none, as shown in the above pic). Note that the friction properties in the Physic Materials don't affect the tire friction.

Camera Controller #

The component VP Camera Controller controls the camera movement based on the target vehicle and several camera modes available.

VP Camera Controller

Source code and internal details #

These are the actual folders for the Vehicle Physics Pro project:

Vehicle Physics Pro project folders

The vehicle physics scripts are inside the Vehicle Physics core folder. The main script to look at is the Vehicle Controller component at Components\VPVehicleController.cs. This component inherits from VehiclePhysics.VehicleBase and overrides its virtual methods for implementing the vehicle's internals using the available blocks: (engine, gearbox, differential...). VehicleBase at Core\VehicleBase.cs manages the integration solver and the wheels, which computes the the final tire forces.

Vehicles are internally modeled as a graph of connected blocks that derive from VehiclePhysics.Block. Each block can receive input torques and produce output torques. Wheels are blocks that receive torques at their inputs. Motors are blocks that produce torques at their outputs. Other blocks have torque inputs and torque outputs. This allows to simulate any kind of internal configuration of the vehicle by connecting blocks in any combination.

Vehicle blocks are created, initialized and connected within the VPVehicleController.cs script, OnInitialize method. Check out the comments in the file VehicleBase.cs for indications on how the vehicles are implemented and simulated by overriding the virtual methods.