public void Update(EngineComponent engine)
            {
                if (!useForcedInduction)
                {
                    return;
                }

                float throttle  = engine.throttlePosition;
                float factor    = throttle * engine.RPMPercent;
                float targetRPM = maxRPM * Mathf.Pow(factor, 1f + 1f - linearity);

                if (forcedInductionType == ForcedInductionType.Turbocharger)
                {
                    if (hasWastegate && engine.throttlePosition < 0.5f && boost > 0.3f)
                    {
                        wastegateFlag  = true;
                        wastegateBoost = boost;
                        RPM            = 0f;
                    }
                    else
                    {
                        RPM = Mathf.SmoothDamp(RPM, targetRPM, ref spoolVelocity, spoolUpTime);
                    }
                }
                else
                {
                    RPM = targetRPM;
                }


                RPM   = RPM > maxRPM ? maxRPM : RPM < 0 ? 0 : RPM;
                boost = RPM * RPM / (maxRPM * maxRPM);
            }
Beispiel #2
0
        public void Solve()
        {
            int componentCount = _components.Count;

            if (componentCount == 0)
            {
                return;
            }

            _iterations = (int)physicsQuality;
            _dt         = Time.fixedDeltaTime * (1f / _iterations);

            // OnPreSolve
            for (int i = 0; i < componentCount; i++)
            {
                _components[i].OnPreSolve();
            }

            // Integrate
            EngineComponent engine = _components[0] as EngineComponent;
            ClutchComponent clutch = _components[1] as ClutchComponent;

            for (int i = 0; i < _iterations; i++)
            {
                engine.clutchEnagagement = clutch.clutchEngagement;
                engine.Integrate(_dt, i);
            }

            // OnPostSolve
            for (int i = 0; i < componentCount; i++)
            {
                _components[i].OnPostSolve();
            }
        }