Last modified 5 years ago Last modified on 2012-03-09 13:09:45

CarVisuals

Provides the visual effects for the wheels, including suspension, rotation, steering, skidmarks and smoke.

This is script is added at the root GameObject for the vehicle, together with the CarControl script. The script needs a global Skidmarks object to be present at the scene. Use the Skidmarks prefab from the Prebafs folder. The Skidmarks object has a child object SkidSmoke which provides the particle emitter and renderer for the smoke effects.

PivotFL, PivotFR, PivotRL, PivotRR

References to the pivot GameObjects for each wheel.

Each pivot GameObject is located at the vehicle's local position for each wheel. Pivots will be moved vertically (suspension) and the front ones will be rotated around their local Y axis (steering). These GameObjects are the proper placeholders for disc brake meshes, which doesn't rotate with the wheel but respond to suspension and steering (example: Sport Coupe). If no disc brakes are used in the model, then use empty GameObjects (example: Bus).

MeshFL, MeshFR, MeshRL, MeshRR

References to the GameObjects representing each wheel and tire. These are the 3D meshes for the wheels.

These GameObjects must be child of their respective pivots. They will be rotated around X axis as the normal wheel rotation when the vehicle moves.

Steering wheel

A reference to the GameObject containing the steering wheel, if available. It must be properly located and orientated at the proper position. The GameObject will be rotated around its local Z axis according to current steering angle. The maximum angle for the steering wheel is configured at the property steeringWheelMax.

Ignored colliders

This parameter is necessary when the vehicle's rigidbody is configured to use interpolation (RigidBody > Interpolate). In that case, add here any collider of the vehicle that overlaps or is close to the WheelCollider objects. This is neccesary because the interpolation could interfere with the Raycasts used for determining the wheel's vertical position, so strange visual effects can occur if the colliders are not ignored.

Skidmarks parameters

These values are defined in terms of the tire's skid ratio:

  • 0 .. 1.0: tire is not skidding, it's conserving all its grip. 1.0 means the slip value at which the tire performs the maximum grip.
  • 1.0 .. 2.0: tire is beginning to loose its grip as consequence of the increasing slip. 2.0 means the slip value at which the tire reaches its minimum grip and is heavily skidding.
  • > 2.0: tire is heavily skidding at its minimum grip value. The slip value in m/s that has surpassed the point of minimum force is this value minus 2.0. Example: a relative skid ratio of 4.0 means the tire is skidding at the slip value of minimum grip + 2 m/s.

The relative skid ratio can be seen in real time in the Telemetry values FSR and SSR for each wheel (key B at the Live Demo). The Friction line shows the slip values for maximum and minimum grip, for both forward (F) and sideways (S) curves.

forwardSkidmarksBegin: skid ratio where the skidmark begins to appear as consequence of accelerating / braking.

forwardSkidmarksRange: range of skid ratio where the skidmark increases its intensity progressively according to the forward slip (accelerate / brake).

sidewaysSkidmarksBegin: skid ratio where the skidmark begins to appear as consequence of sideways slip (drifting).

sidewayskidmarksRange: range of skid ratio where the skidmark increases its intensity progressively according to the sideways slip (drift).

skidmarksWidth (m): use for match the skidmarks' width with the wheel's width.

skidmarksOffset (m): use for properly align the skidmarks with the wheels.

Skidmarks example:

Telemetry: 
    WheelFL RPM:   0 S: 0.50 F: 6007 FS:-1.50 SS: 0.94 FSR:-1.00 SSR: 0.27
    Friction F: [1.500, 2.500] S: [3.500, 6.000]

The forwards skid ratio (FSR) is 1.0 when the forward slip (FS) is 1.500 m/s, and is 2.0 when the slip is 2.500 m/s. The further slip values in m/s are directly added to the the ratio. For example, if the forward slip value is 7 m/s, the skid ratio results in 2.0 + (7 - 2.500) = 6.5, which means "4.5 m/s above the slip value where the skid ratio is 2.0 (2.500 m/s)".

forwardSkidmarksBegin = 1.5
forwardSkidmarksRange = 5.0

Skidmarks will start appearing when the forward slip (FS, accelerate / brake) is 2 m/s (forwardSkidmarksBegin = 1.5 = half way between 1.500 and 2.500). The skidmarks appear at their maximum intensity at the skid ratio forwardSkidmarksBegin+forwardSkidmarksRange = 1.5 + 5.0 = 6.5. This skid ratio means 4.5 m/s above the slip value corresponding to the ratio 2.0. So the slip for the maximum intensity is 4.5 + 2.500 = 7 m/s.

Smoke parameters

These values are also defined as skid ratio (see above):

forwardSmokeBegin: minimum skid ratio where the smoke can start appearing as consequence of forward slip (burnouts, brake lock)

forwardSmokeRange: range of forward skid ratio where the smoke increases its intensity progressively.

sidewaysSmokeBegin: minimum skid ratio where the smoke can start appearing as consequence of sideways slip (drifting).

sidewaysSmokeRange: range of sideways skid ratio where the smoke increases its intensity propgressively.

The smoke is also controlled by the time that the tire's slip is inside the smoke range. When the tire's skid ratio reaches the SmokeBegin value, time starts counting forward. When the skid ratio decreases below the SmokeBegin value, time counts reverse. This allows to control the smoke's intensity according to the time and frequency the wheel enters into the "smoke zone". It's like a kind of tire's temperature, but just counting the heating-cooling time instead of degrees.

smokeStartTime: time in seconds that the tire must be in the smoke's skid range in order to begin emitting smoke. 0 means that the smoke starts as soon as the tire's reaches the SmokeBegin value.

smokePeakTime: time in seconds the tire takes to reach the maximum smoke intensity.

smokeMaxTime: maximum time that is counted while the tire's skid ratio is over SmokeBegin. Note that this value could be smaller than smokePeakTime, so the smoke never reaches the maximum intensity.

Smoke example:

smokeStartTime = 2
smokePeakTime = 12
smokeMaxTime = 24

Provided that the tire is performing a continuous burnout, then:

  • 2 seconds after starting the burnout the tire starts emitting very small traces of smoke, which begin growing progressively.
  • 10 seconds later (at second 12) the tire is generating smoke at maximum intensity.
  • The burnout continues during at least other 12 seconds (total seconds: 24 or more), maximum smoke intensity.

When the burnout ends the time will count reverse:

  • The tire will take 12 seconds to "start cooling". During those 12 seconds, if the burnout restarts the smoke will already begin at its maximum intensity.
  • The next 10 seconds, the tire will be "cooling" progressively. If the burnout restarts, the smoke will begin at the corresponding intensity.
  • The next 2 seconds the tire won't emit smoke if the burnout restarts, just the time will count forward.

Other settings

wheelGroundedBias: distance in meters the wheels are placed intersecting the ground. This simulates the deformation as consequence of the vehicle's weight.

steeringWheelMax: maximum rotation degrees the steering wheel can rotate in each direction. Used for moving the steering wheel according to the user's input.