void OnCollisionEnter2D(Collision2D other) { // if this is homeplanet and it collided with a normal planet, game over if (this.tag == "HomePlanet" && other.gameObject.tag == "Planet") { GameObject.FindGameObjectWithTag("GameManager").GetComponent <GameManager>().StopGameRunning(); } // if this is a planet-planet collision, the current planet is being moved by pushForce and the two planet havent just interacted with each other else if (this.tag == "Planet" && other.gameObject.tag == "Planet" && pushForce != Vector2.zero && other.gameObject != lastInteractedObj) { PlanetScript otherPlanet = other.gameObject.GetComponent <PlanetScript>(); SetLastInteractedObj(otherPlanet.gameObject); otherPlanet.SetLastInteractedObj(this.gameObject); Vector3 damageDirection = (other.transform.position - this.transform.position).normalized; this.TakeDamage(damageDirection, false); collidedAfterPush = true; otherPlanet.TakeDamage(-damageDirection, false); } }
// 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; } }