void OnTriggerEnter(Collider collision) { if (collision.CompareTag("Skier")) // Will be called if collision with a skier occurs. { Vector3 explosionPos = transform.position; // explosion will occur at the impact site. explosionPos.y = 0; //Make sure that there is no y component Collider[] colliders = Physics.OverlapSphere(explosionPos, radius); // List of colliders within the radius. // animation for the door TetheredMineAnimation.SetBool("IsDoorClosed", true); TetheredMineAnimation.SetBool("IsDoorOpen", false); // Hatch Close Door sound AudioManager.Play("TetherObs&BBHatchDoorClosed"); AudioManager.Play("TetheredMineExplosion"); foreach (Collider hit in colliders) //For all the objects in the radius, { if (hit.CompareTag("Skier")) //If this object is a skier, { SkierController controller = hit.GetComponent <SkierController>(); // Gets all controllers within the radius. if (!controller.IsInvincible()) { controller.HurtSkier(); // Hurts the skier within the radius. } } } ControllerVibrate.VibrateAll(1.0f, 0.5f); //Vibrate all controllers very moderately gameObject.SetActive(false); // Deactivates the mine. m_rb.velocity = Vector3.zero; // Resets velocity. m_rb.angularVelocity = Vector3.zero; // Resets angular velocity. m_rb.transform.rotation = Quaternion.Euler(Vector3.zero); // Resets rotation. m_tmAbility.setIsUsingAbility(false); m_tmAbility.mineAbilityCooldown.SetTimer(); explosionPrefab.transform.position = explosionPos; //Make the explosion happen at the right spot Instantiate(explosionPrefab); //Create the explosion GameFreezer.Freeze(freezeAmount, freezeFrames); //Slow time very briefly for impact } else if (collision.CompareTag("Rock")) //If colliding with an obstacle, { float pushDirection = transform.position.x - collision.transform.position.x; //Calculate if the mine should be pushed left or right if (pushDirection > 0) //If positive, { m_tether.ForceOverTime(new Vector3(m_tmAbility.obstacleForce, 0, 0), m_tmAbility.obstacleForceDuration); //Push right } else //If negative, { m_tether.ForceOverTime(new Vector3(-m_tmAbility.obstacleForce, 0, 0), m_tmAbility.obstacleForceDuration); //Push left } } }
void OnCollisionEnter(Collision collision) { if (collision.gameObject.CompareTag("River")) // Will be called if collision with the river occurs. { Vector3 explosionPos = transform.position; // explosion will occur at the impact site. explosionPos.y = 0; //Make sure that there is no y component Collider[] colliders = Physics.OverlapSphere(explosionPos, m_bbAbility.radius); // List of colliders within the radius. AudioManager.Play("BeachBomb POP"); foreach (Collider hit in colliders) //For all the objects in the radius, { if (hit.CompareTag("Skier")) //If this object is a skier, { Tether tether = hit.GetComponent <Tether>(); //Get their tether Vector3 distanceToHit = hit.transform.position - explosionPos; //Get the difference in position between the skier and the explosion point distanceToHit.y = 0; //Make sure there is no y compenent Vector3 extraForwardsForce = new Vector3(0, 0, m_bbAbility.extraForwardsPower); //Make an extra force up the river to account for always moving forwards Vector3 totalForce = m_bbAbility.power * distanceToHit.normalized + extraForwardsForce; //Total up the forces tether.ForceOverTime(totalForce, m_bbAbility.forceDuration); //Add a force on the skier, pushing away from the explosion point } else if (hit.CompareTag("Mine")) { Tether tether = hit.GetComponent <Tether>(); //Get their tether Vector3 distanceToHit = hit.transform.position - explosionPos; //Get the difference in position between the skier and the explosion point distanceToHit.y = 0; //Make sure there is no y compenent Vector3 extraForwardsForce = new Vector3(0, 0, m_bbAbility.extraForwardsPower); //Make an extra force up the river to account for always moving forwards Vector3 totalForce = m_bbAbility.minePower * distanceToHit.normalized + extraForwardsForce; //Total up the forces tether.ForceOverTime(totalForce, m_bbAbility.forceDuration); //Add a force on the mine, pushing away from the explosion point } } gameObject.SetActive(false); // Deactivates the beachball. m_rb.velocity = Vector3.zero; // Resets velocity. m_rb.angularVelocity = Vector3.zero; // Resets angular velocity. m_rb.transform.rotation = Quaternion.Euler(Vector3.zero); // Resets rotation. m_bbAbility.ToggleIsShooting(false); // Player isn't shooting anymore. m_bbAbility.ToggleMeshEnable(false); // Disabled target's mesh. explosionPrefab.transform.position = explosionPos; //Make the explosion happen at the right spot Instantiate(explosionPrefab); //Create the explosion ControllerVibrate.VibrateAll(0.2f, 0.5f); //Vibrate all controllers a meduim amount GameFreezer.Freeze(freezeAmount, freezeFrames); //Slow time very briefly for impact } }
private static int m_frames; //How many frames to make the acceleration to normal speed take private void Awake() { instance = this; //Set the instance to itself }