private void Start() { wheelMeshLocalRotations = new Quaternion[4]; wheelColliderFrictionInfos = new WheelColliderFrictionInfo[4]; for (int i = 0; i < 4; i++) { wheelMeshLocalRotations[i] = wheelMeshes[i].transform.localRotation; wheelColliderFrictionInfos[i] = new WheelColliderFrictionInfo(wheelColliders[i]); } rigidBody = GetComponent <Rigidbody>(); rigidBody.centerOfMass = centerOfMassOffset; currentTorque = totalTorque - (tractionControl * totalTorque); }
// Either set all wheel colliders to zero friction, or reset them to defaults public void WheelCollidersFriction(bool wantFriction) { for (int i = 0; i < 4; i++) { WheelCollider wheelCollider = wheelColliders[i]; WheelFrictionCurve forwardCurve = wheelCollider.forwardFriction; WheelFrictionCurve sidewaysCurve = wheelCollider.sidewaysFriction; // Return to original values if (wantFriction) { WheelColliderFrictionInfo originalInfo = wheelColliderFrictionInfos[i]; //forwardCurve.extremumValue = originalInfo.forwardExtremumValue; //forwardCurve.asymptoteValue = originalInfo.forwardAsymptoteValue; sidewaysCurve.extremumValue = originalInfo.sidewaysExtremumValue; sidewaysCurve.asymptoteValue = originalInfo.sidewaysAsymptoteValue; // tractionControl = 0.25f; steerHelper = 0.5f; } // Set frictions to minimum else { //forwardCurve.extremumValue = 0.0f; //forwardCurve.asymptoteValue = 0.0f; sidewaysCurve.extremumValue = 0.0f; sidewaysCurve.asymptoteValue = 0.0f; tractionControl = 0.0f; steerHelper = 0.0f; } wheelCollider.forwardFriction = forwardCurve; wheelCollider.sidewaysFriction = sidewaysCurve; } }