コード例 #1
0
    protected virtual void FixedUpdate()
    {
        maxThrottle = 1;
        oldSteering = steering;
        velo        = cardynamics.velo;
        veloKmh     = cardynamics.velo * 3.6f;
        bool onGround = drivetrain.OnGround();

        if (smoothInput)
        {
            SmoothSteer();
            smoothThrottle();
            smoothBrakes();
        }
        else
        {
            steering = steerInput;
            brake    = brakeInput;
            throttle = throttleInput;
            if (drivetrain.changingGear && drivetrain.automatic)
            {
                throttle = 0;
            }
        }

        // Steer Assistance (limits steering to optimal steer angle)
        if (steerAssistance && drivetrain.ratio > 0 && veloKmh > SteerAssistanceMinVelocity)      //we enablesteerAssistance only for speed > SteerAssistanceMinVelocity (in km/h)
        {
            SteerAssistance();
        }
        else
        {
            steerTimer = 0;
            maxSteer   = 1;
        }


        TCSTriggered = false;
        if (TCS && drivetrain.ratio > 0 && drivetrain.clutch.GetClutchPosition() >= 0.9f && onGround && throttle > drivetrain.idlethrottle && veloKmh > TCSMinVelocity)   //we enable TCS only for speed > TCSMinVelocity (in km/h)
        {
            DoTCS();
        }

        ESPTriggered = false;
        if (ESP && drivetrain.ratio > 0 && onGround && veloKmh > ESPMinVelocity)       //we enable ESP only for speed > ESPMinVelocity (in km/h)
        {
            DoESP();
        }

        ABSTriggered = false;
        if (ABS && brake > 0 && veloKmh > ABSMinVelocity && onGround)          //we enable ABS only for speed > ABSMinVelocity (in km/h)
        {
            DoABS();
        }

        float mmaxThrottle;

        if (drivetrain.gearRatios[drivetrain.gear] > 0)
        {
            mmaxThrottle = maxThrottle;
        }
        else
        {
            mmaxThrottle = maxThrottleInReverse;
        }

        if (drivetrain.revLimiterTriggered)
        {
            throttle = 0;
        }
        else if (drivetrain.revLimiterReleased)
        {
            throttle = throttleInput;
        }
        else
        {
            throttle = Mathf.Clamp(throttle, drivetrain.idlethrottle, mmaxThrottle);
        }

        brake         = Mathf.Clamp01(brake);
        steering      = Mathf.Clamp(steering, -1, 1);
        deltaSteering = steering - oldSteering;

        // Apply inputs
        foreach (Wheel w in allWheels)
        {
            if (!(ABS && veloKmh > ABSMinVelocity && brakeInput > 0))
            {
                w.brake = brake;                                                                 // if ABS is on, brakes are applied by ABS directly
            }
            w.handbrake     = handbrakeInput;
            w.steering      = steering;
            w.deltaSteering = deltaSteering;
        }

        drivetrain.throttle = throttle;
        if (drivetrain.clutch != null)
        {
            if (clutchInput != 0 || drivetrain.autoClutch == false)
            {
                drivetrain.clutch.SetClutchPosition(1 - clutchInput);
            }
        }

        drivetrain.startEngine = startEngineInput;
    }