Vehicle tuning (client realm)¶
vehicle.DriveModel and vehicle.WheelSetup read and write the handling
parameters of a wheeled vehicle at runtime. DriveModel holds the
chassis-wide values; WheelSetup holds the per-wheel values and takes a wheel
index. Both run in the client realm, on the client that simulates the vehicle.
Both act on a vehicle.WheeledBaseObject. Get one from the vehicle the local
player is in:
var gi = ScriptGameInstance.Get();
var player = ScriptGameInstance.GetPlayerSystem(gi)?.GetLocalPlayerControlledGameObject();
var veh = player is null
? null
: Global.GetMountedVehicle(player).Upgrade()?.Cast<vehicle.WheeledBaseObject>();
if (veh is null)
{
return; // the local player is not in a wheeled vehicle
}
// chassis-wide: double the steering lock
var maxTurn = vehicle.DriveModel.GetMaxWheelTurnDeg(veh);
vehicle.DriveModel.SetMaxWheelTurnDeg(veh, maxTurn * 2.0f);
// per wheel: soften every wheel's spring
for (byte wheel = 0; wheel < 4; wheel++)
{
var k = vehicle.WheelSetup.GetSpringStiffness(veh, wheel);
vehicle.WheelSetup.SetSpringStiffness(veh, wheel, k * 0.5f);
}
Every parameter is a Get<Field>(veh) / Set<Field>(veh, value) pair on
vehicle.DriveModel, and a Get<Field>(veh, wheel) /
Set<Field>(veh, wheel, value) pair on vehicle.WheelSetup — all float.
The field set mirrors the vehicle's drive-model and wheel-preset records, so
the names match the members of vehicle.DriveModel / vehicle.WheelSetup (and
the VehicleDriveModelData, VehicleWheelDrivingPreset and
VehicleWheelDimensionsPreset records). Some of the common ones:
vehicle.DriveModel (chassis) |
Fields |
|---|---|
| Steering | MaxWheelTurnDeg, WheelTurnMaxAddPerSecond, WheelTurnMaxSubPerSecond |
| Grip / slip | SlipAngleCurveScale, SlipRatioCurveScale, SlopeTractionReductionFactor |
| Braking | BrakingFrictionFactor, HandbrakeBrakingTorque, LowVelStoppingDeceleration |
| Weight transfer | ForwardWeightTransferFactor, SideWeightTransferFactor |
| Body | AirResistanceFactor, TurningRollFactor |
vehicle.WheelSetup (per wheel) |
Fields |
|---|---|
| Tire | TireFrictionCoef, TireRollingResistanceCoef, FrictionMulLateral, FrictionMulLongitudinal |
| Suspension | SpringStiffness, SpringDamping, SpringReboundDamping, SwaybarStiffness |
| Wheel | Mass, MaxBrakingTorque |
Read the stock values from the vehicle's record with veh.GetRecord() first if
you want to scale from or restore the defaults rather than hardcode numbers.
Note
Tuning applies to the vehicle instance in the client realm where you set it — the client that simulates that car. It changes how that car drives there; it is not a persistent edit of the vehicle record.