Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

Question How i make car engine rev limit?

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

  1. driftnumata

    driftnumata

    Joined:
    May 31, 2023
    Posts:
    28
    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.         }