// sends player off a planet and blows it up public void LeavePlanet(float chargeTime) { // make sure there is a currentplanet and the player can jump off it if (isLanded && currentPlanet != null && canJump) { isLanded = false; transform.parent = null; canJump = false; playerAudio.PlayLeavingSound(); Vector2 leavingAngle = new Vector2(transform.position.x - currentPlanet.transform.position.x, transform.position.y - currentPlanet.transform.position.y).normalized; // TODO: check if applyForce is better float leavingSpeed = maxChargeSpeed / 2f; if (chargeTime >= maxChargeTime) { leavingSpeed = maxChargeSpeed; } if (activatedPowerup == PowerupScript.PowerupType.lighting) { leavingSpeed *= powerupSpeed; } GetComponent <Rigidbody2D>().velocity = leavingAngle * leavingSpeed; GetComponent <Rigidbody2D>().freezeRotation = false; // consume powerLevel //powerLevel -= powerLevelUsedOnJump; // kills the other player if they're on this planet and it will explode if (otherPlayer.isDead == false && otherPlayer.currentPlanet != null && otherPlayer.currentPlanet.gameObject == this.currentPlanet.gameObject && currentPlanet.WillExplodeNext()) { otherPlayer.Suicide(); } // if the planet will explode, get points if (currentPlanet.WillExplodeNext()) { AcquirePoints(currentPlanet.GetPointValue(), this.transform.position); } nearbyPlanets.Remove(currentPlanet.gameObject); currentPlanet.SelfDestruct(); currentPlanet = null; } }
// sends player off a planet and blows it up public void LeavePlanet(float chargeTime) { // make sure there is a currentplanet and the player can jump off it if (isLanded && currentPlanet != null && canJump) { isLanded = false; transform.parent = null; canJump = false; StartCoroutine(EnableTail(true, 0f)); playerAudio.PlayLeavingSound(); float chargePercentage = Mathf.Clamp(chargeTime / maxChargeTime, 0f, 1f); leavingSpeed = maxChargeSpeed * (2f + chargePercentage) / 3f; Vector2 leavingDirection = (Vector2)(transform.position - currentPlanet.transform.position).normalized; //if (activatedPowerup == PowerupScript.PowerupType.lighting){ // leavingSpeed *= powerupSpeed; //} myRigidBody.velocity = leavingDirection * leavingSpeed; myRigidBody.freezeRotation = false; lastPlanet = currentPlanet; // crack/destroy the planet if it's not the home planet if (currentPlanet.tag != "HomePlanet") { // if the planet will not explode, push it if (!currentPlanet.WillExplodeNext()) { float pushPower = planetPushPower * (1f + chargePercentage * 1f); currentPlanet.PushPlanet(-leavingDirection, pushPower); } currentPlanet.TakeDamage(leavingDirection, true); } currentPlanet = null; } }