コード例 #1
0
    // at each update: //
    private void Update()
    {
        // if either: the locomotion dependencies are met, the stuck failsafe dependencies are met: //
        if (locomotionDependencies.areMet() || dependenciesStuckFailsafe.areMet())
        {
            // if: regular gauge treading is controlled via toggling (instead of holding), regular gauge input just began: invert the tracking of whether the regular treading toggle is on //
            if (!heldVersusToggled && locomotionInputEnabledAndAllowed() && controller.inputPressing(inputsLocomotion))
            {
                regularTreadingToggle = !regularTreadingToggle;
            }
            // if regular gauge treading is not controlled via toggling or locomotion input is not enabled: ensure that the regular gauge treading toggle is off //
            if (heldVersusToggled || !locomotionInputEnabledAndAllowed())
            {
                regularTreadingToggle = false;
            }

            // if this treader is experiencing significant input: //
            if (experiencingSignificantInput())
            {
                // if a gauge of treading is beginning: broadcast the treading gauge beginning event //
                if (controller.inputPressing(inputsLocomotion) || controller.inputTouching(inputsLocomotion))
                {
                    // broadcast treading gauge beginning event //
                    if (treadingGaugeBeginningEvent != null)
                    {
                        treadingGaugeBeginningEvent();
                    }
                }

                // based on whether any touchpad input is being used: determine the max treading speed //
                float maxSpeed = 0f;                                                                                                       // initialize the max treading speed to 0
                if (controller.inputTouched(inputsLocomotion))                                                                             // if any touchpad input is being used: set the max treading speed to the corresponding max treading speed gauge:
                {
                    maxSpeed = ((controller.touchpadPressed || !slowerSpeedEnabled || regularTreadingToggle) ? speedMax : slowerSpeedMax); // if the touchpad is being pressed or the slower guage speed is disabled or regular treading is currently toggled on: use the normal gauge; otherwise (if the touchpad is merely significantly being touched): use the slower gauge
                }
                else                                                                                                                       // otherwise (if no touchpad input is being used): simply set the max treading speed to the normal max treading speed setting
                {
                    maxSpeed = speedMax;
                }

                // initialize the treading velocity (which is just for x and z) as a proportionality (that is, without scaling it to the appropriate magnitude/speed yet) //
                Vector3 treadingVelocityProportionalityForwardPart   = FloatsVector.zeroes; // define the forward part to be the forward direction of this treader
                Vector3 treadingVelocityProportionalityRightwardPart = FloatsVector.zeroes; // initialize the rightward part as a zeroes vector
                if (controller.inputTouched(inputsLocomotion))                              // if any touchpad input is being used: proportion the velocity parts based on the touchpad input position's coordinates' signage
                {
                    // proportion the forward part of the velocity based on the touchpad's y (used for z) input position //
                    treadingVelocityProportionalityForwardPart = directionReferenceTransform.forward * controller.touchpadY;

                    // proportion the rightward part of the velocity based on the touchpad's x input position //
                    treadingVelocityProportionalityRightwardPart = directionReferenceTransform.right * controller.touchpadX;
                }
                else                            // otherwise (if no touchpad input is being used): only proportion the treading velocity forward part – using the forward direction of this treader
                {
                    treadingVelocityProportionalityForwardPart = directionReferenceTransform.forward;
                }
                Vector3 treadingVelocity = treadingVelocityProportionalityForwardPart + treadingVelocityProportionalityRightwardPart;                           // initialize the treading velocity as the sum of both the forward and rightward parts

                // trim out the y axis of the treading velocity //
                treadingVelocity = treadingVelocity.withYZero();

                // calculate the treading speed //
                float speed = 0f;                               // initialize the treading speed to 0
                if (controller.inputTouched(inputsLocomotion))  // if any touchpad input is being used:
                {
                    // set the speed to be the max treading speed, curved by the distance of the input position on the touchpad away from the center, using the curve setting //
                    speed = touchpadSpeedDistanceCurve.clamped(0f, maxSpeed, controller.touchpadDistance);
                }
                else                            // otherwise (if no touchpad input is being used): simply set the treading speed to the max treading speed
                {
                    speed = speedMax;
                }

                // scale the treading velocity to the calculated treading speed //
                treadingVelocity = treadingVelocity.normalized * speed;

                // if the player's speed in the direction of the treading velocity is not yet at or past the treading velocity's speed: //
                if (Vector3.Dot(MoonMotionPlayer.velocity, treadingVelocity.normalized) < speed)
                {
                    // determine the appropriate responsiveness factor //
                    float appropriateResponsivnessFactor = responsivenessFactorSkiing;
                    if (!Skier.skiing)
                    {
                        bool driftingWithinOneSecondAgo = dependencyDriftingWithinOneSecondAgo.isMet();
                        if (!driftingWithinOneSecondAgo)
                        {
                            appropriateResponsivnessFactor = responsivenessFactorNonskiingNondrifting;
                        }
                        else
                        {
                            float timeAgoDriftingBoosting  = (Time.time - BoostingDriftingTracker.timePlayerWasLastBoostingDrifting);
                            float timeAgoDriftingLaunching = (Time.time - LaunchingDriftingTracker.timePlayerWasLastLaunchingDrifting);
                            float timeAgoDrifting          = Mathf.Min(timeAgoDriftingBoosting, timeAgoDriftingLaunching);

                            appropriateResponsivnessFactor = responsivenessFactorNonskiingDriftingCurve.clamped(responsivenessFactorNonskiingDriftingMin, responsivenessFactorNonskiingDriftingMax, (timeAgoDrifting / 1f));
                        }
                    }

                    // hone the player's velocity x and z axes to the treading velocity x and z axes by the determined treading velocity x and z axes' magnitudes in proportion to the current frame's duration times the appropriate responsivness factor //
                    Vector3 honingVector = treadingVelocity.magnitudes().withYZero() * Time.deltaTime * appropriateResponsivnessFactor;
                    playerRigidbody.velocity = MoonMotionPlayer.velocity.honedTo(treadingVelocity, honingVector);
                }
            }
            // otherwise (if this treader is not currently experiencing significant input): if the player is not currently skiing: //
            else if (!Skier.skiing)
            {
                // determine whether significant input is currently ceasing //
                bool significantInputCeasing = (locomotionInputEnabledAndAllowed() && (controller.inputUnpressing(inputsLocomotion) || controller.inputUntouching(inputsLocomotion)));

                // determine whether the other treader is currently experiencing significant input //
                bool otherTreaderIsCurrentlyExperiencingSignificantInput = (otherTreaderActive() && other.experiencingSignificantInput());

                // if: this treader is currently ceasing to experience significant input, the other treader is not currently experiencing significant input //
                if (significantInputCeasing && !otherTreaderIsCurrentlyExperiencingSignificantInput)
                {
                    // stop the player's x and z movement (zero the player velocity's x and z axes) //
                    playerRigidbody.velocity = MoonMotionPlayer.velocity.withXAndZZero();
                }
            }
        }
    }
コード例 #2
0
 // method: determine whether the player is currently treading (regardless of whether they are actually significantly moving as a result) //
 public static bool treading()
 => ((isActive(left) && left.experiencingSignificantInput()) || (isActive(right) && right.experiencingSignificantInput()));