Ejemplo n.º 1
0
    // updating //


    // at the start: connect to defueler instances //
    protected override void Start()
    {
        base.Start();

        if (leftInstance)
        {
            left = this;
        }
        else
        {
            right = this;
        }
    }
Ejemplo n.º 2
0
    // at each physics update: //
    private void FixedUpdate()
    {
        // fuel production
        // (updated alongside physics so that it stays in sync with the fuel usage drawn by boosting forces (such that if, for example, fuel force is produced at a rate of 100, and the force being applied is 100, the current fuel force amount will not change))
        BoosterFuelSupply.addFuelForce(this, BoosterRefueler.productionAmount(this));

        // determining whether this booster's automator is currently automating //
        bool automating = BoosterAutomator.automating(this);

        // boosting inputting, modules handling, and corresponding updating //
        if (!BoosterHalter.halted(this) && ((BoosterToggler.enabledBoosting(this) && locomotionInputEnabledAndAllowed() && controller.inputPressed(inputsLocomotion)) || automating))             // if this booster's halter isn't currently halting boosting, and either boosting is enabled while the input is pressed at all or this booster's automator is automating
        {
            // initializing boosting values //
            float  forceShallow       = BoosterForceApplier.amountShallow(this);
            float  forceDeep          = BoosterForceApplier.amountDeep(this);
            float  forceAmount        = (forceShallow + forceDeep) / 2f;
            ushort vibrationIntensity = BoosterVibrator.intensityShallow(this);

            // determining the currently accessible fuel amount //
            float accessibleFuelAmount = BoosterFuelSupply.accessibleFuelForce(this);

            // determine whether the deep force fuel threshold is met by either being "swung open" (like a floodgate) by already deep boosting, or by being at or above the deep force fuel threshold (per Booster Force Applier) //
            bool deepForceFuelThresholdMet = (boostingDeeply || (accessibleFuelAmount >= BoosterForceApplier.fuelThresholdForBooster(this)));

            // determining whether the booster automator is using fuel //
            bool automatorUsingFuel = BoosterAutomator.usingFuel(this);

            // determining whether there is enough fuel for shallow force boosting andor deep force boosting //
            bool enoughFuelForShallowForce = ((accessibleFuelAmount >= forceShallow) || (automating && !automatorUsingFuel));
            bool enoughFuelForDeepForce    = ((accessibleFuelAmount >= forceDeep) && deepForceFuelThresholdMet);

            // determining boosting values - shallow //
            if ((!controller.inputDeeped(inputsLocomotion) && enoughFuelForShallowForce) || (controller.inputDeeped(inputsLocomotion) && !enoughFuelForDeepForce && enoughFuelForShallowForce))                         // whether either is true: the input is not deeped and there is enough fuel for shallow force, the input is deeped but there is not enough fuel for deep force yet there is enough fuel for shallow force
            {
                boosting       = true;
                boostingDeeply = false;

                forceAmount        = forceShallow;
                vibrationIntensity = BoosterVibrator.intensityShallow(this);
            }
            // determining boosting values - deep //
            else if (enoughFuelForDeepForce)                            // otherwise (if the input is deeped), if there is enough fuel for deep force
            {
                boosting       = true;
                boostingDeeply = true;

                forceAmount        = forceDeep;
                vibrationIntensity = BoosterVibrator.intensityDeep(this);
            }
            // determining to not be boosting due to lack of fuel, and having the fuel sputtering play accordingly (if actually inputting) //
            else
            {
                boosting       = false;
                boostingDeeply = false;

                if (controller.inputPressing(inputsLocomotion))                         // only if this booster is receiving input, since the Booster Automator is smart enough to not try to boost when there is no fuel so it doesn't sputter
                {
                    BoosterFuelSputterer.sputter(this);
                }
            }

            // boosting (if at least shallow force is boosting) //
            if (boosting)
            {
                // determine the player's current velocity //
                Vector3 currentPlayerVelocity = PlayerVelocityReader.velocity();
                // determining the rotation vector for the force direction relative to this booster //
                Vector3 forceDirectionRelative = BoosterForceApplier.direction(this).asDirectionRelativeTo(BoosterRelativizer.relativityTransform(this));
                // determining the speed of the player's rigidbody in the direction of the booster's force aiming //
                float bodySpeedInBoosterDirection = Vector3.Dot(currentPlayerVelocity, forceDirectionRelative);
                // fuel usage via Booster Defueler //
                if (!(automating && !automatorUsingFuel))                               // only if not automatically boosting without using fuel
                {
                    BoosterDefueler.defuel(this, forceAmount);
                }
                // application of boosting force //
                if (!BoosterSpeedLimiter.speedLimited(this) || (bodySpeedInBoosterDirection < BoosterSpeedLimiter.boosterSpeedLimit(this)))                       // if limiting the speed is currently unecessary
                {
                    // boosting force to apply (in the specified direction (originally/ by default, opposite the expelling of the booster)) //
                    Vector3 forceToApply = forceDirectionRelative * forceAmount * Time.fixedDeltaTime;
                    forceToApply *= BoosterForceMultiplier.forceFactor(this);                     // adjust the force to apply by the force factor provided by the corresponding Booster Force Multiplier
                    if (BoosterPulser.pulsingForcePercentage(this) != 0f)                         // add the pulsing force (based on the corresponding Booster Pulser) to the force to apply
                    {
                        if (BoosterPulser.pulsingPlayerUpDirectionOnly(this))
                        {
                            Vector3 playerUpDirection           = BasicDirection.up.asDirectionRelativeTo(playerTransform);
                            float   forceToApplyForPlayerUpOnly = Vector3.Dot(forceToApply, playerUpDirection);
                            forceToApply += (playerUpDirection * forceToApplyForPlayerUpOnly * BoosterPulser.pulsingForcePercentage(this) * Mathf.Sin(Time.time / BoosterPulser.pulsingForceFrequency(this)));
                        }
                        else
                        {
                            forceToApply += (forceToApply * BoosterPulser.pulsingForcePercentage(this) * Mathf.Sin(Time.time / BoosterPulser.pulsingForceFrequency(this)));
                        }
                    }
                    if (BoosterAntidiminisher.antidiminishingBooster(this))                                              // if this booster's Booster Antidiminisher is currently antidiminishing this booster
                    {
                        forceToApply = Vector3.Scale(-forceToApply, BoosterAntidiminisher.antidiminishingFactors(this)); // reverse the force to apply and antidiminish it based on this booster's Booster Antidiminisher
                    }
                    else if (BoosterDiminisher.diminished(this))                                                         // if this booster's Booster Diminisher is currently diminishing this booster
                    {
                        if ((bodySpeedInBoosterDirection + Vector3.Dot(forceToApply, forceDirectionRelative)) > 0f)      // if the speed the player's rigidbody will have in the booster direction after force application is greater than 0
                        {
                            forceToApply = Vector3.Scale(forceToApply, BoosterDiminisher.diminishingFactors(this));      // diminish the force to apply based on this booster's Booster Diminisher
                        }
                    }
                    // inertia dampening //
                    if (BoosterInertiaDampener.inertiaDampened(this) && (bodySpeedInBoosterDirection < forceToApply.magnitude))
                    {
                        Vector3 inertiaDampeningForceToApply = (forceDirectionRelative * Vector3.Dot(currentPlayerVelocity, -forceDirectionRelative) * BoosterInertiaDampener.dampeningFactor(this));
                        playerRigidbody.AddForce(inertiaDampeningForceToApply);
                    }
                    // application of boosting force //
                    BoosterForceApplier.applyForce(this, forceToApply);
                }
                // fall dampening //
                if (BoosterFallDampener.fallDampened(this) && (currentPlayerVelocity.y < 0) && ((forceDirectionRelative - playerTransform.up).y > -.25f))                         // if fall dampening is enabled and the rigidbody is going down and this controller is boosting against that direction by at least about 45°
                {
                    Vector3 fallDampeningForceToApply = (playerTransform.up * BoosterFallDampener.dampeningForce(this) * Time.fixedDeltaTime);
                    playerRigidbody.AddForce(fallDampeningForceToApply);
                }
                // vibrating of controller //
                controller.vibrate(vibrationIntensity);
            }
        }


        else                    // otherwise (if no input nor module is having boosting happen currently): determining to not be boosting
        {
            boosting       = false;
            boostingDeeply = false;
        }
    }