Colliders : Triggers vs Collisions

PHOTO EMBED

Sun Aug 08 2021 20:36:09 GMT+0000 (UTC)

Saved by @thepapayaki #c#

private void OnTriggerEnter(Collider other) {
  if (other.CompareTag("Powerup")){
    Destroy(other.gameObject);
    isPoweredUp = true;
    powerupIndicator.SetActive(true);
    StartCoroutine(PowerupCountdownRoutine());
  }
}

private void OnCollisionEnter(Collision other) {
  if (other.gameObject.CompareTag("Enemy") && isPoweredUp){
    Rigidbody enemyRB = other.gameObject.GetComponent<Rigidbody>();
    Vector3 awayFromPlayer = (other.gameObject.transform.position - transform.position);
    enemyRB.AddForce(awayFromPlayer * powerupStrength, ForceMode.Impulse);
  }
}
content_copyCOPY