Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

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.