//Collision Enter checker: checks if collided with player void OnCollisionEnter(Collision collision) { Collider collider = collision.collider; //Checks if hit a player or another enemy if (collider.tag == "Player") { hitEnemy = true; //Set variables up to calculate knockback direction Vector3 victimPos = collider.bounds.center; Vector3 thisPos = thisBody.position; //Create self-recoil package to self DamagePackage dmgPackage = new DamagePackage(0f); dmgPackage.setCentralizedKnockback(victimPos, thisPos, SELF_KNOCKBACK); getDamage(dmgPackage); //Gives recoil //Create damage package to send to player dmgPackage.setCentralizedKnockback(thisPos, victimPos, KNOCKBACK); dmgPackage.setDamage(bodyDamage); //Send damagePackage collider.gameObject.SendMessage("getDamage", dmgPackage); } }
//Triggers shockwave damage to elements in affected // Pre: targetTag must be either "Player" or "Enemy" private void triggerShockwave(Collider detonator) { //Creates new damage package to send DamagePackage dmgPackage = new DamagePackage(shockwaveDamage); //Establishes DSource Transform dSource = (detonator.tag == "EnemyAttack" && detonator.GetComponent <ProjectileStatus>().source != null) ? detonator.GetComponent <ProjectileStatus>().source : detonator.transform.root; //Sends knockback depending on each suspect and sends damagePackage if suspect is a target foreach (Collider suspect in effected) { if (suspect != null) //Checks if object hasn't been deleted //Reverses all time effects { if (suspect.tag == "Enemy" || suspect.tag == "EnemyAttack" || suspect.tag == "PausedProjectile") { suspect.SendMessage("applySlow", 1 / SLOW_FACTOR); } //Applies damage to everyone in the field except the one who detonated it. Applies to players and enemies. Not attacks if (suspect.transform != dSource && (suspect.tag == "Player" || suspect.tag == "Enemy")) { dmgPackage.setCentralizedKnockback(detonator.transform.position, suspect.transform.position, shockwaveKnockback); suspect.SendMessage("getDamage", dmgPackage); } } } }
//Deal damage void OnTriggerEnter(Collider other) { if (other.tag == "Player") { dmgPackage.setCentralizedKnockback(GetComponent <Transform>().position, other.transform.position, KNOCKBACK); other.SendMessage("getDamage", dmgPackage); } }