Ejemplo n.º 1
0
    // upon trigger entry: //
    private void OnTriggerEnter(Collider collider)
    {
        // code for: gravitizing rigidbodies, player zonage toggling //

        // track any potential rigidbody (local or parent) of the given collider for being gravitized – if it has not been tracked yet //
        Transform rigidbodyTransform = collider.selfOrAncestorTransformWith <Rigidbody>(); // find the transform of this collider's rigidbody, if it has one locally or as a parent; otherwise, determine no transform (null) for this collider's rigidbody transform

        if (rigidbodyTransform)                                                            // if this collider does have a rigidbody (by checking the determined rigidbody transform)
        {
            // determine the rigidbody of this collider (based on the determined rigidbody transform) //
            Rigidbody rigidbodyOfCollider = rigidbodyTransform.GetComponent <Rigidbody>();

            // if: this rigidbody is set to use gravity, this rigidbody has not yet been tracked as one of the rigidbodies to gravitize: //
            if (rigidbodyOfCollider.useGravity && !rigidbodiesToGravitize.Contains(rigidbodyOfCollider))
            {
                // track this collider's rigidbody as one of the rigidbodies to gravitize //
                rigidbodiesToGravitize.Add(rigidbodyOfCollider);

                // if this collider belongs to the player: //
                if (collider.GetComponentInParent <Player>())
                {
                    // toggle the player zonage according to this zone's entry toggling //
                    toggleZonageForPlayerEntry();

                    // if Terrain Response's liftoff audio is set to play upon player entry into this gravity zone: //
                    if (playLiftoffAudioUponPlayerEntry && (gravitizingEnabled || !audioRequiresGravitizing))
                    {
                        // have Terrain Response play random liftoff audio //
                        TerrainResponse.playRandomLiftoffAudio();
                    }
                }
            }
        }
    }
Ejemplo n.º 2
0
    // at each update: //
    private void Update()
    {
        // if: the player is ready to jump, the player is terrained or midair jumping is available, locomotion input is enabled and allowed, locomotion input is pressing, this jumper's priority is not overridden: //
        if (JumpingSettings.jumpingReady() && (TerrainResponse.terrained() || JumpingSettings.midairJumpingAvailable()) && locomotionInputEnabledAndAllowed() && controller.inputPressing(inputsLocomotion) && !priorityOverridden())
        {
            // handle midair jumping //
            if (!TerrainResponse.terrained())
            {
                Vector3 playerVelocity = PlayerVelocityReader.velocity();

                if (midairJumpingReplacesVelocity && ((playerVelocity.y < forceAmount) || (Flipper.flipped && (playerVelocity.y > -forceAmount))))
                {
                    playerRigidbody.velocity = new Vector3(playerVelocity.x, 0f, playerVelocity.z);
                }

                if (!JumpingSettings.midairJumpingInfinite())
                {
                    JumpingSettings.decrementMidairJumpsCount();
                }
            }

            // play the attached jumping audio //
            playJumpingAudio();

            // change the player's velocity for this jumping //
            playerRigidbody.velocity += new Vector3(0f, (Flipper.flipped ? -forceAmount : forceAmount), 0f);

            // have Jumping Settings track the time of the last jump as right now //
            JumpingSettings.trackTimeOfLastJump();
        }
    }
Ejemplo n.º 3
0
    // methods //


    // method: play audio for player exiting from the all of the Gravity Zones if applicable (and update tracking for the time of last playing accordingly) //
    private static void applicablyPlayAudioForExitFromTheAll()
    {
        if (singleton.playLiftoffAudioUponAllExit && (((Time.time - lastTimeWithinNonzerolyAffectingGravityZonage) <= 1f) || !singleton.audioRequiresAffectation))
        {
            if ((Time.time - timeOfLastLiftoffAudioPlaying) >= TerrainResponse.singleton.liftoffAudioSet.longestLength())
            {
                TerrainResponse.playRandomLiftoffAudio();

                timeOfLastLiftoffAudioPlaying = Time.time;
            }
        }
    }
    // updating //


    // at each update: //
    public override void update()
    {
        // if the number of midair jumps provided is -1 (standing for infinity): set the midair jumps count to -1 (standing for infinity)
        if (midairJumpsProvided == -1)
        {
            midairJumpsCount = -1;
        }
        // if the player is terrained: //
        if (TerrainResponse.terrained())
        {
            // if the midair jumps count is lower than the number of jumps provided: raise the midair jumps count to the number of jumps provided //
            if (midairJumpsCount < midairJumpsProvided)
            {
                midairJumpsCount = midairJumpsProvided;
            }
        }
    }
 // at each update: playing emission accordingly //
 private void Update()
 {
     // if the booster is boosting as necessary: //
     if (dependencies.areMet())
     {
         // if the player is grounded or the smoke ring is allowed to play when nongrounded and the player is terrained: track that the player was terrained at the last update //
         if (TerrainResponse.grounded() || (smokeRingWhenNongrounded && TerrainResponse.terrained()))
         {
             appropriatelyTerrainedAtLastUpdate = true;
         }
         // otherwise: if the player was terrained at the last update: track that the player was not terrained at the last update, play one round of emission of the booster smoke ring emitter //
         else if (appropriatelyTerrainedAtLastUpdate)
         {
             appropriatelyTerrainedAtLastUpdate = false;
             emitter.Play();
         }
     }
 }
Ejemplo n.º 6
0
    // methods //


    // method: determine the (boolean) state of this Dependency Requisite //
    public override bool state()
    {
        return(TerrainResponse.grounded());
    }
Ejemplo n.º 7
0
    // method: calculate the distance of the booster to the nearest recognized (according to Terrain Response) terrain in the direction of the booster's boosting; this also tracks for Booster Antidiminisher whether the booster is at distance to an antidiminishor //
    public static float distanceToTerrain(Booster booster)
    {
        // connect to the diminisher for the given booster //
        BoosterDiminisher diminisher = diminisherFor(booster);

        // determine any nontrigger colliders that this diminisher's hand is currently inside of (according to Hand Insideness Tracking) //
        HashSet <GameObject> allCollidedObjects = (booster.leftInstance ? HandInsidenessTracking.allCollidedObjectsForLeftHand() : HandInsidenessTracking.allCollidedObjectsForRightHand());

        // if this diminisher's hand is currently inside of any nontrigger collider objects: //
        if (allCollidedObjects.Count > 0)
        {
            // if any of the objects this diminisher's hand is inside of is on a recognized terrain layer: calculate the distance to the nearest recognized terrain to be 0 //
            foreach (GameObject collidedObject in allCollidedObjects)
            {
                if (TerrainResponse.recognizedTypedTerrainLayerIndex(diminisher.recognizedTerrainType, collidedObject.layer))
                {
                    diminisher.terrainDistancingLastFoundObstruction = false;                                   // track that obstruction was not found for this terrain distancing
                    return(0f);
                }
            }
            // otherwise: track that an obstruction was found for this terrain distancing, and consider the distance to terrain to be -1, as a flag of no recognized terrain being found //
            diminisher.terrainDistancingLastFoundObstruction = true;
            return(-1f);
        }
        // otherwise: determine the distance to the nearest recognized terrain via raycasting //
        else
        {
            // track that obstruction was not found for this terrain distancing //
            diminisher.terrainDistancingLastFoundObstruction = false;


            // determine the relativity transform that this booster's relativizer is using currently //
            Transform relativityTransform = BoosterRelativizer.relativityTransform(booster);


            // if there is a recognized terrain below, calculate distance based on that //

            RaycastHit[] raycastHitsFound = Physics.RaycastAll(relativityTransform.position, -BoosterForceApplier.direction(booster).asDirectionRelativeTo(relativityTransform), Mathf.Infinity, Physics.DefaultRaycastLayers);                         // get all raycast hits for raycasting from the booster in the direction of the booster's force
            if (Any.itemsIn(raycastHitsFound))
            {
                // determine the nearest raycast hit found's: hit distance, hit //
                float      nearestRaycastHitDistance = Mathf.Infinity;                          // initialize the nearest raycast hit's distance
                RaycastHit nearestRaycastHit         = raycastHitsFound[0];                     // initialize the nearest raycast hit to the first raycast hit found, by default (since it can't be null)
                foreach (RaycastHit raycastHitFound in raycastHitsFound)
                {
                    if (hitTriggerColliders || !raycastHitFound.collider.isTrigger)                                            // if trigger collider hits are allowed, or this raycast did not hit a trigger collider
                    {
                        float raycastHitFoundDistance = Vector3.Distance(relativityTransform.position, raycastHitFound.point); // determine this raycast's hit distance
                        // if this raycast's hit distance is less than the smallest distance found thus far, update the tracked nearest raycast hit and its distance to this raycast's //
                        if (raycastHitFoundDistance < nearestRaycastHitDistance)
                        {
                            nearestRaycastHitDistance = raycastHitFoundDistance;
                            nearestRaycastHit         = raycastHitFound;
                        }
                    }
                }

                // if the nearest raycast hit found is legal (based on the following conditions): track whether this diminisher is at distance to an antidiminisher, return the nearest raycast's hit distance //
                if (hitTriggerColliders || !nearestRaycastHit.collider.isTrigger)                                                                                                                                                                                                                                                      // if trigger collider hits are allowed, or the nearest raycast did not hit a trigger collider
                {
                    if (TerrainResponse.recognizedTypedTerrainLayerIndex(diminisher.recognizedTerrainType, nearestRaycastHit.transform.gameObject.layer))                                                                                                                                                                              // if the nearest raycast hit recognized terrain
                    {
                        BoosterAntidiminisher.antidiminisherFor(booster).atDistanceToAntidiminishor = BoosterAntidiminisher.antidiminishorLayer(nearestRaycastHit.transform.gameObject.layer) && (nearestRaycastHitDistance >= 0f) && (nearestRaycastHitDistance <= BoosterAntidiminisher.boosterAntidiminishingDistanceMax(booster)); // track whether this booster is at distance to an antidiminisher
                        return(nearestRaycastHitDistance);                                                                                                                                                                                                                                                                             // return the nearest raycast's hit distance
                    }
                }
                // otherwise (if the nearest raycast hit found is not legal): //
                else
                {
                    // track that this booster is not at distance to an antidiminisher //
                    BoosterAntidiminisher.antidiminisherFor(booster).atDistanceToAntidiminishor = false;
                }
            }
            // otherwise (if no raycast hits were found): //
            else
            {
                // track that this booster is not at distance to an antidiminisher //
                BoosterAntidiminisher.antidiminisherFor(booster).atDistanceToAntidiminishor = false;
            }

            // if nothing has been returned yet: consider the distance to terrain to be -1, as a flag of no recognized terrain being found (not 0, because returning 0 (as could have been returned above) would have indicated that recognized terrain was found at an immediate distance) //
            return(-1f);
        }
    }
Ejemplo n.º 8
0
    // methods //


    // method: determine the (boolean) state of this Dependency Requisite //
    public override bool state()
    {
        return(TerrainResponse.terrained());
    }
Ejemplo n.º 9
0
    // methods //


    // method: determine the (boolean) state of this Dependency Requisite //
    public override bool state()
    {
        return(TerrainResponse.collidedWithTerrain());
    }
    // methods //


    // method: determine the (boolean) state of this Dependency Requisite //
    public override bool state()
    {
        return(TerrainResponse.withinAirNonrushingDistanceToTerrainBelow());
    }