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:
The vehicles in all these scenes typically begin with the engine off. For starting the engine:
- Press K for moving the ignition key from "Off" to "Drive" (check out the telemetry window)
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.
|K||Ignition key||Press to move from "Off" to "Drive". Press and Hold for "Start". ctrl+K moves the key back to "Off".|
|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|
|F1-F4||Select different camera modes|
|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:
- Center Of Mass: references the position of the center of mass in the vehicle.
- Inertia: configures the distribution of mass in the vehicle. Affects understeering / oversteering behavior.
- Axes: references to the wheels and assigns steering and brakes to them.
- Steering: steering angle, ackerman, toe.
- Brakes: brake torques, balance, handbrake.
- Tires: tire friction model and parameters.
- Driveline: driveline type and component setup (differentials, torque splitter). Current setup is RWD with a Torque Splitter dynamically routing part of the drive to the front axle.
- Engine: torque and power curves, rpm limiter, stall settings.
- Clutch: type of clutch and parameters. Using a torque converter is very handy when a real clutch simulation (Disc Friction) is not required.
- Gearbox: transmission type, gear ratios, auto-shift parameters.
- Retarder: typically used by heavy vehicles, not used at the pickup (zero levels).
- Advanced / Experimental settings: leave then untouched for now. Learn more
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:
Other components #
The other components present at the Vehicle gameobject provide different add-on functionalities and features:
- 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.
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.
Source code and internal details #
These are the actual folders for the Vehicle Physics Pro project:
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
VehiclePhysics.VehicleBase and overrides its virtual methods for implementing the
vehicle's internals using the available blocks: (engine, gearbox,
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
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
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.