Esempio n. 1
0
    // helper function that resets the player to initial drifting state
    private void ResetPlayerStates()
    {
        isDead                    = false;
        isLanded                  = false;
        canJump                   = false;
        currentChargeTime         = 0f;
        canAction                 = false;
        takingAction              = false;
        currentActionChargeTime   = 0f;
        actionChargesUsable       = 0;
        transform.parent          = null;
        currentPlanet             = null;
        lastPlanet                = null;
        currentAntiStuckForceTime = 0f;
        leavingSpeed              = 0f;

        chargeBar.SetActive(false);
        jetpackFlame.SetActive(false);
        activatedPowerup = PowerupScript.PowerupType.none;
        powerupCountdown = 0;
        powerupEffect.DeactivateAllEffects();
        transform.position    = initialPosition;      // TODO: need better method for respawn
        transform.eulerAngles = initialRotation;
        nearbyPlanets.Clear();
    }
Esempio n. 2
0
    // helper function that resets the player to initial drifting state
    private void ResetPlayerStates()
    {
        isDead           = false;
        isLanded         = false;
        canJump          = false;
        transform.parent = null;
        currentPlanet    = null;
        activatedPowerup = PowerupScript.PowerupType.none;
        powerupCountdown = 0;
        powerupEffect.DeactivateAllEffects();
        coinCombo             = 0;
        transform.position    = initialPosition;
        transform.eulerAngles = initialRotation;
        //powerLevel = powerLevelInitial;
        nearbyPlanets.Clear();

        // give a starting velocity to nearest planet. if no planets exist, then just assign random velocity
        float      startingSpeed   = 5f;
        GameObject nearestPlanet   = null;
        float      nearestDistance = 9999f;

        foreach (GameObject planet in GameObject.FindGameObjectsWithTag("Planet"))
        {
            float newDistance = Vector3.Distance(planet.transform.position, transform.position);
            if (newDistance < nearestDistance)
            {
                nearestDistance = newDistance;
                nearestPlanet   = planet;
            }
        }
        if (nearestPlanet != null)
        {
            Vector2 startingDirection = (nearestPlanet.transform.position - transform.position).normalized;
            GetComponent <Rigidbody2D>().velocity = startingDirection * startingSpeed;
        }
        else
        {
            float angle = Random.Range(0, 360) * Mathf.Deg2Rad;
            GetComponent <Rigidbody2D>().velocity = new Vector2(Mathf.Cos(angle) * startingSpeed,
                                                                Mathf.Sin(angle) * startingSpeed);
        }
    }