// Update is called once per frame
    void Update()
    {
        if (_vehicleInput != null)
        {
            if (!_vehicleInput.getStatus())
            {
                return;
            }
        }
        getInput();

        // Basic Ability Call
        if (offensiveAbility != null && offensiveTrigger && abilitiesActivated)
        {
            if (fireAbility(offensiveAbility, _canUseBasic, offensiveFillBar, offensiveBrightIcon, offensiveAbilityBG, 'o'))
            {
                _canUseBasic = false;
                offensiveAbility.AbilityInUse();
                StartCoroutine(OffensiveAbilityCooldown());
            }
        }

        // Signature Ability Call
        if (defensiveAbility != null && defensiveTrigger && abilitiesActivated)
        {
            if (fireAbility(defensiveAbility, _canUseDefensiveAbility, defensiveAbilityFillAmount, defensiveBrightIcon, DefensiveAbilityBG, 'd'))
            {
                _canUseDefensiveAbility = false;
                defensiveAbility.AbilityInUse();
                StartCoroutine(DefensiveAbilityCooldown());
                StartCoroutine(DefensiveAbilityDuration());
            }
        }

        // Boost Ability Call
        if (boostAbility != null && boostTrigger && abilitiesActivated)
        {
            if (fireAbility(boostAbility, _canBoost, boostFillBar, boostBrightIcon, BoostAbilityBG, 'b'))
            {
                _canBoost = false;
                boostAbility.AbilityInUse();
                StartCoroutine(BoostAbilityCooldown());
                StartCoroutine(BoostAbilityDuration());
                rayCastCar.isBoosting = true;
                //    StartCoroutine(ChangeFOV());
                AudioManager.instance.Play("Boost", transform);
            }
        }
    }
Example #2
0
 void checkInput()
 {
     // If there is no vehicle input then this is an AI Carand the AI Car will set the inputs.
     if (input != null)
     {
         if (input.getStatus())
         {
             horizontal = Input.GetAxis(input.horizontal);
             throttle   = Input.GetAxis(input.verticalForward);
             reverse    = Input.GetAxis(input.verticalBackward);
             //drift = Input.GetButton(input.brake);
         }
         else
         {
             horizontal = 0f;
             throttle   = 0f;
             reverse    = 0f;
             drift      = false;
         }
     }
 }
    // Update is called once per frame
    void Update()
    {
        float extraSpeed = 0;

        // If vehicle input is turned off don't listen to inputs
        if (!_vehicleInput.getStatus())
        {
            tiltShift.blurArea = Mathf.Min(_maxBlurArea * (Mathf.Pow(currentSpeed, _blurScaling) / Mathf.Pow(topSpeed, _blurScaling)), 1);
            return;
        }

        //Takes input for forward and reverse movement

        if (_isBoosting)
        {
            extraSpeed += ((_boostSpeedPercentage * topSpeed) / 100);
        }
        if (_isOnBoosterPad)
        {
            extraSpeed += ((_boosterPadSpeedPercentage * topSpeed) / 100);
        }

        speed = (topSpeed + extraSpeed) * (Input.GetAxis(_vehicleInput.verticalForward) - Input.GetAxis(_vehicleInput.verticalBackward));

        //Allows for vehicle to back up and break
        if (speed < 0)
        {
            speed *= reverseSpeed;
        }
        if (Input.GetButtonUp(_vehicleInput.brake))
        {
            _drifting = false;
        }

        //Drifting mechanics
        if (Input.GetAxis(_vehicleInput.horizontal) != 0)
        {
            //values are clamped to a specific usable range
            int   dir    = Input.GetAxis(_vehicleInput.horizontal) > 0 ? 1 : -1;
            float amount = Mathf.Abs(Input.GetAxis(_vehicleInput.horizontal));

            //Checks necessary conditions for drifting to happen
            if (Input.GetButtonDown(_vehicleInput.brake) && !_drifting && Input.GetAxis(_vehicleInput.horizontal) != 0)
            {
                if (driftSound != null) //placed here just so that the BallCar prefab doesn't throw nulls
                {
                    driftSound.Play();
                }

                _drifting       = true;
                _driftDirection = Input.GetAxis(_vehicleInput.horizontal) > 0 ? 1 : -1;

                if (leftDriftParticles != null && rightDriftParticles != null) //placed here just so that the BallCar prefab doesn't throw nulls
                {
                    if (_driftDirection == 1)
                    {
                        leftDriftParticles.SetActive(true);
                    }
                    else if (_driftDirection == -1)
                    {
                        rightDriftParticles.SetActive(true);
                    }
                }
                else
                {
                    //placed here just so that the BallCar prefab doesn't throw nulls
                    //Delete this later
                    //Debug.Log("Drift Particles are null, please assign them!");
                }
            }
            if (_drifting)
            {
                DriftAudioSource.enabled = true;
                driftButton.sprite       = driftSpriteDown;
                //Remaps the user input values to appropriate amounts to allow drifting
                amount = (_driftDirection == 1) ? ExtensionMethods.Remap(Input.GetAxis(_vehicleInput.horizontal), -1, 1, 0, 1 + driftStrength) : ExtensionMethods.Remap(Input.GetAxis(_vehicleInput.horizontal), -1, 1, 1 + driftStrength, 0);
            }
            else
            {
                DriftAudioSource.enabled = false;
            }

            //passes in appropriate turning values based on drifting bool
            if (_drifting)
            {
                Steer(_driftDirection, amount);
            }
            else
            {
                if (driftSound != null)  //placed here just so that the BallCar prefab doesn't throw nulls

                {
                    driftSound.Stop();
                }
                driftButton.sprite = driftSpriteUp;
                if (leftDriftParticles != null && rightDriftParticles != null) //placed here just so that the BallCar prefab doesn't throw nulls
                {
                    leftDriftParticles.SetActive(false);
                    rightDriftParticles.SetActive(false);
                }
                Steer(dir, amount);
            }
        }

        //hitOn/hitNear check and rotate the vehicle body up and down based on direction of the track
        RaycastHit hitOn;

        Physics.Raycast(sphere.transform.position, -kartNormal.transform.up, out hitOn, 2f, layerMask);

        //Next we are getting the difference between down and the direction we will apply gravity so we can similarly adjust how we apply regular movement
        Quaternion forceRotation = new Quaternion();

        if (hitOn.collider != null)
        {
            //calculating the angle in radians then converting it to degrees
            forceRotation = Quaternion.FromToRotation(Vector3.down, -hitOn.normal);
        }
        //Ties the vehicle body to the sphere collider
        transform.position = sphere.transform.position - (forceRotation * new Vector3(0, 0.4f, 0));

        //Checks if the vehicle should be reversing or not, and evenly increases speed based on that.
        if (Mathf.Abs(speed) >= Mathf.Abs(currentSpeed) || speed * currentSpeed > 0)
        {
            currentSpeed = Mathf.SmoothStep(currentSpeed, speed, Time.deltaTime * acceleration); speed = 0f;
        }
        else
        {
            currentSpeed = Mathf.SmoothStep(currentSpeed, speed, Time.deltaTime * deceleration); speed = 0f;
        }

        //Smoothly changes the vehicle's rotation
        currentRotate = Mathf.Lerp(currentRotate, rotate, Time.deltaTime * 4f); rotate = 0f;

        //Motion Blur for car speed right now 7 and 10 are the magic numbers for the effect we are looking for
        tiltShift.blurArea = Mathf.Min(_maxBlurArea * (Mathf.Pow(currentSpeed, _blurScaling) / Mathf.Pow(topSpeed, _blurScaling)), 1);

        if (speedometerImage != null)
        {
            speedometerImage.fillAmount = currentSpeed / topSpeed; //Speedometer code
        }
        else
        {
            //remove this once UI gets replaced
        }

        if (Input.GetButtonDown(_vehicleInput.rightStickButton))
        {
            aimOn = !aimOn;
        }
    }