Ejemplo n.º 1
0
    private void Update()
    {
        //Debug.Log(Vector3.Distance(transform.position, _localTarget));
        if (Vector3.Distance(transform.position, _localTarget) < trackerSensitivity)
        {
            //Debug.Log("got here");
            if (progressPercentage >= 1f)
            {
                progressPercentage = 0f;
            }
            else
            {
                progressPercentage += precision;
                //Debug.Log(progressPercentage);
            }
            _localTarget = path.GetPoint(progressPercentage);
        }


        Vector3 localTargetTransform = transform.InverseTransformPoint(path.GetPoint(progressPercentage));

        _targetAngle = (localTargetTransform.x / localTargetTransform.magnitude);


        float speedFactor  = _carController.GetCurrentSpeed() / _carController.GetMaximumSpeed();
        float corner       = Mathf.Clamp(Mathf.Abs(_targetAngle), 0, 90);
        float cornerFactor = corner / 90.0f;

        float brake = 0;

        if (corner > 10 && speedFactor > 0.05f)
        {
            brake = Mathf.Lerp(0, 1 + speedFactor * brakeFactor, cornerFactor);
        }

        float accel = 1f;

        if (corner > 20 && speedFactor > 1f)
        {
            accel = Mathf.Lerp(0, 1 * accelerationCareFactor, 1 - cornerFactor);
        }

        if (!manualOverride)
        {
            // _carController.MoveVehicle(accel, brake, _targetAngle);

            if (_carController.GetCurrentSpeed() >= aimedSpeed)
            {
                brake += 50f;
                _carController.MoveVehicle(accel, brake, _targetAngle);
            }
            else
            {
                _carController.MoveVehicle(accel, brake, _targetAngle);
            }
        }
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        float brakeInput        = Input.GetAxis("Jump");
        float accelerationInput = Input.GetAxis("Vertical");   // W or Arrow up acceleration forward or backwards.
        float steeringInput     = Input.GetAxis("Horizontal"); //A or D steering

        if (steeringInput != 0 || accelerationInput != 0 || brakeInput != 0)
        {
            ManualDriving = true;
            _carController.MoveVehicle(accelerationInput, brakeInput, steeringInput);
        }
        else
        {
            ManualDriving = false;
        }
    }