Search Unity

Question How i make car engine rev limit?

Discussion in 'Getting Started' started by driftnumata, May 31, 2023.

Thread Status:
Not open for further replies.
  1. driftnumata

    driftnumata

    Joined:
    May 31, 2023
    Posts:
    29
    Hello, I'm making car controller.
    But,the engine rpm continues to rotate indefinitely. So, how can you limit the rpm of the engine so that it does not spin any more?

    ↓↓This is my project's script.

    Code (CSharp):
    1. engineRPM = Mathf.Lerp(engineRPM, Mathf.Max(idleRPM + wheelsRPM * gearRatios[currentGear] * differentialRatio), Time.deltaTime * 3f);
    2.  
    3.         if (0 < KPH)
    4.         {
    5.             currentTorque = (engineTorqueCurve.Evaluate(engineRPM / revLimitRPM) * maxEngineTorque) * gearRatios[currentGear] * differentialRatio * 0.7f / WheelColliders[3].radius * throttle;
    6.         }
    7.         else
    8.         {
    9.             if (!isBraking)
    10.             {
    11.                 currentTorque = engineTorqueCurve.Evaluate(engineRPM / revLimitRPM) * -reversGearRatio * differentialRatio * throttle * maxEngineTorque;
    12.             }
    13.         }
     
Thread Status:
Not open for further replies.