Example #1
0
    void ApplyMotorTorque(float torque)
    {
        if (carController.TCS)
        {
            WheelHit hit;
            wheelCollider.GetGroundHit(out hit);

            if (Mathf.Abs(wheelCollider.rpm) >= 100)
            {
                if (hit.forwardSlip > .25f)
                {
                    carController.TCSAct = true;
                    torque -= Mathf.Clamp(torque * (hit.forwardSlip) * carController.TCSStrength, 0f, carController.engineTorque);
                }
                else
                {
                    carController.TCSAct = false;
                    torque += Mathf.Clamp(torque * (hit.forwardSlip) * carController.TCSStrength, -carController.engineTorque, 0f);
                }
            }
            else
            {
                carController.TCSAct = false;
            }
        }

        if (OverTorque())
        {
            torque = 0;
        }

        wheelCollider.motorTorque = ((torque * (1 - carController.clutchInput) * carController._boostInput) * carController._gasInput) * (carController.engineTorqueCurve[carController.currentGear].Evaluate(wheelRPMToSpeed * carController.direction) * carController.direction);

        carController.ApplyEngineSound(wheelCollider.motorTorque);
    }