Exemple #1
0
    // helper function that lands the player onto a given planet
    public void LandOnPlanet(GameObject planet)
    {
        // make sure that the player hasn't already landed
        if (isLanded == false && currentPlanet == null)
        {
            isLanded = true;
            canJump  = true;            // TODO: implement a brief delay when you land where you can't jump
            // clear coin combo
            coinCombo     = 0;
            currentPlanet = planet.GetComponent <PlanetScript>();
            playerAudio.PlayLandingSound();

            // rotates and repositions the player accordingly
            Vector3 difference = transform.position - currentPlanet.transform.position;
            float   radius     = currentPlanet.gameObject.GetComponent <CircleCollider2D>().radius *currentPlanet.transform.lossyScale.x +
                                 GetComponent <BoxCollider2D>().size.y *transform.lossyScale.x / 2;
            Vector3 newDifference = difference.normalized * radius;
            transform.position = transform.position - difference + newDifference;
            RotateToPlanet();

            GetComponent <Rigidbody2D>().freezeRotation = true;
            transform.parent = planet.transform;
            nearbyPlanets.Remove(currentPlanet.gameObject);
        }
        else
        {
            print("Error: cannot land on " + planet.name);
        }
    }
Exemple #2
0
    // helper function that lands the player onto a given planet
    public void LandOnPlanet(GameObject planet)
    {
        // make sure that the player hasn't already landed
        if (isLanded == false && currentPlanet == null)
        {
            isLanded     = true;
            canJump      = true;        // TODO: implement a brief delay when you land where you can't jump
            canAction    = false;
            takingAction = false;
            currentAntiStuckForceTime = 0f;
            cumulatedGravityPullForce = Vector2.zero;
            StartCoroutine(EnableTail(false, 1f));

            // clear coin combo
            currentPlanet = planet.GetComponent <PlanetScript>();
            playerAudio.PlayLandingSound();

            // rotates and repositions the player accordingly
            StandOnCurrentPlanet();
            RotateToCurrentPlanet();

            myRigidBody.freezeRotation = true;
            transform.parent           = planet.transform;
            nearbyPlanets.Remove(currentPlanet.gameObject);
            // TODO: clean this up
            if (currentPlanet.gameObject.tag == "HomePlanet" && currentPlanet.rotationSpeed != homePlanetRotationSpeed)
            {
                currentPlanet.rotationSpeed = homePlanetRotationSpeed;
            }
        }
        else
        {
            Debug.Log("Error: cannot land on " + planet.name);
        }
    }