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

CarControl

Main script for controlling and configuring the vehicle. All parameters that affect the behavior & handling are defined here (except suspension parameters: spring, damper, distance, radius, which are configured on each wheel).

This is script is added to the root GameObject of the vehicle.

WheelFL, WheelFR, WheelRL, WheelRR:

References to the four WheelCollider components of the vehicle. Each physic wheel is a GameObject containing a WheelCollider component and a CarWheel script.

AntiRollFront, AntiRollRear:

References to the AntiRollBar scripts. These scripts are typically added also to the vehicle's root GameObject.

CenterOfMass:

Reference to an empty child GameObject positioned at the vehicle's Center Of Mass.

ForwardWheelFriction, SidewaysWheelFriction:

Parameters of the forward and sideways friction curves. Use the tire telemetry (CarTelemetry, B then shift-B at the Live Demo) for showing the resulting curve in real-time. Ensure the optimized property (below) to be disabled when modifying these parameters in real-time.

(Typical parameter range in parenthesis)

  • grip (100..2500): grip factor. The bigger, the more difficult is to make the tire to slide. Too much sideways grip can cause the vehicle to roll over on curves. The forward grip is internally adjusted to match the maximum forward acceleration defined at motorPerformancePeak.

  • gripRange (1..8): amount of slip in m/s on which the tire can keep its strong grip. The slip value at which the tire offers the maximum force is usually within the first half of this value, then it starts losing grip.

  • drift (50..800, should be equal or smaller than grip): grip factor when the tire slip has surpased the limit gripRange+1. The less value, the more grip is lost when the slip limit is reached.

  • driftSlope (-0.1..+0.1): amount of grip factor that is gained (positive) or lost (negative) when the tire slip increases below gripRange+1. 0 means constant factor at any slip over the limit.

Optimized: Disable for adjusting the Friction Curves in real-time. If enabled, the interal parameters for the Friction Curves are calculated only once at the beginning. Keep disabled for development & fine tunning, enable for deploying the project.

Input parameters

The CarMain script controls these input parameters, and allows to switch among several vehicles. Here you can configure the steerMax, motorMax, and brakeMax properties.

steerInput (-1.0..+1.0): action on the steering wheel. -1 = full left, 0 = centered, +1 = full right. The maximum steering angle in degrees is set at steerMax.

motorInput (0..1.0): action on the accelerator (throttle). The maximum amount of slip in m/s applied to the drive wheels when motorInput is 1.0 is set at motorMax.

brakeInput (0..1.0): action on the brakes. The maximum amount of braking slip in m/s applied to the wheels when brakeInput is 1.0 is set at brakeMax.

handBrakeInput (0..1.0): action on the hand brake. 1.0 means rear wheels are locked.

gearInput (-1..+1): gear, actually only -1 (R), 0 (N) and +1 (D) are available.

steerMax (degrees): maximum wheel steering when steerInput is +-1.

motorMax (m/s): maximum traction slip applied to the drive wheels when motorInput is 1.0.

brakeMax (m/s): maximum braking slip applied to the wheels when brakeInput is 1.0.

motorMax is the maximum amount of slip (in m/s) that will be transferred to the drive wheels. The slip causes the the force at the tire according to the friction parameters. At the Live Demo, the Telemetry shows how much traction slip is being applied (key B, label FS). You can also see graphically how the slip is generating the force at tire (B, then shift-B). Enabling TC (traction control) at CarSettings (key 2 at the Live Demo) limits the slip to the peak value of the friction curve (first of the values after the label Friction at the Telemetry), so the tire generates the maximum force when accelerating.

brakeMax works in the same way but the value is applied when braking. Enabling ABS at CarSettings (key 1 at the Live Demo) limits the slip to the peak value of the friction curve, so the tire generates the maximum force when braking.

Driving aids

The CarSettings script control these parameters, and allows to configure the aids available on each vehicle.

autoSteerLevel (0.0..1.0+): (named as ESP in the Live Demo) limits the steering angle with the speed, so the sideways slip at the front wheels doesn't surpases the tire's maximum force. Values below 1.0 allow bigger steering angles, reaching or surpasing the grip limit accordingly. 0.0 disables this feature.

autoMotorMax: (Traction Control, TC) limits the traction slip to the value of the tire's maximum forward force.

autoBrakeMax: (ABS) limits the braking slip to the value of the tire's maximum forward force.

antiRollLevel (0.0..1.0+): configures the efficiency of the anti-roll bars (AntiRollBar). 1.0 = normal, 0.5 = half force, 0.0 = disabled. Different values here are show as Offroad, Confort and Sport at the Live Demo (red car, key 5 for change this setting).

Performance & behavior parameters

motorPerformancePeak (1.0-10.0): Maximum acceleration in m/s2 that the car would receive when four wheels drive are applying their maximum forward friction force (i.e. when autoMotorMax is enabled), being motorForceFactor = 1.0.

This value defines the maximum theoretical acceleration of the vehicle. It's not an exact value beacuse the maximum tire force is an estimation, and the transfers of masses have influence as well. You must experiment with it until finding the proper acceleration for your vehicle.

If the vehicle is 2 wheels drive, then motorForceFactor (below) should be 2.0 for reaching a similar acceleration (the final value depends on the drive wheels being front or rear, and the mass transfer caused by the acceleration itself).

motorForceFactor (1.0..2.0+): multipler of the grip factors of the forward friction curves when the wheel is applying traction force. Use 1.0 for 4 wheels drive vehicles, 2.0 for 2 wheels drive. Controlled from [[CarSettings]] if available.

motorBalance (0.0..1.0): 0.0 = front wheels drive, 1.0 = rear wheels drive, 0.5 = full wheel drive. Controlled from CarSettings if available.

brakeForceFactor (1.0+): multipler of the grip factors of the forward friction curves when the wheel is applying brake force. Use valores greater than 1.0 for increasing the power of the brakes.

brakeBalance (0.0..1.0): 0.0 = only front brakes, 1.0 = only rear brakes, 0.5 = 50% balanced front-rear.

sidewaysDriftFriction (0.0..1.0): amount of sideways grip the wheels loose when their forward slip exceeds their grip limit (gripRange+1). 0.0 = all grip lost, 0.5 = 50% grip lost, 1.0 = no grip lost.

staticFrictionMax (0..2500): sideways grip factor applied to the wheels at small sideways slip values. Increase this value when the car slides laterally in slopes. 0 to disable.

frontSidewaysGrip, rearSidewaysGrip (0.5..1.2): multipler of the grip factors for the front and rear wheels separately. Allows to fine tune the understeer / oversteer behaviors.

Additional & Experimental settings

serviceMode: puts the script in Service Mode, which enables the raw friction curves without tweakings. Used with CarTest, these settings allows to retrieve the critical data from the friction curves, but has no utility in games.

airDrag: influence of the aerodynamic drag calculated as Cdrag = 0.5 * Cd * A * rho. The value here is Cd*A. Use for establishing a limit for the vehicle's maximum speed.

frictionDrag: a kind of mechanical and rolling friction, calculated as multipler of Cdrag (frictionDrag * Cdrag). The greater this value, the more time takes the vehicle to reach the maximum speed allowed by airDrag.

rollingFrictionSlip (0.01 - 0.1): braking slip in m/s applied to the wheels when moving inertially, without applying throttle or brakes. The greater this value, the quicker the vehicle comes to a stop when there's no throttle nor brake inputs.

tractionV3: enables the experimental traction mode which reduces the traction slip applied to the drive wheels when approaching a predefined maximum speed (maxSpeed). At that value, no traction slip is applied.

The old V2 traction model (by default) applies always the same traction slip regardless of the vehicle's speed, and relies only in the aerodynamic drag for limiting its speed. When using this V3 mode the aerodynamic drag can be set to a realistic value.

maxSpeed (m/s): maximum speed in m/s when using the tractionV3 mode.

UPDATE: Due to the (in)famous WheelCollider bug, reducing the traction slip causes a major loss of sideways slip so the vehicle will likely go out of control. This is especially noticeable in fast vehicles (try enabling tractionV3 in the Sport Coupe). It's recommended NOT to use the tractionV3 option until a new version is released. Use airDrag and frictionDrag for setting the vehicle's acceleration and top speed.