public override void OnHit(Collider2D other) { BaseGameEntity otherObj = other.gameObject.GetComponent <BaseGameEntity>(); Vector2 directionVector = Vector2.right; if (Mathf.Sign(transform.localScale.x) == -1) { directionVector = Vector2.left; } float cs = Mathf.Cos(transform.rotation.eulerAngles.z); float sn = Mathf.Sin(transform.rotation.eulerAngles.z); directionVector = new Vector2(directionVector.x * cs - directionVector.y * sn, directionVector.x * sn + directionVector.y * cs); switch (_animator.currAnim.currFrame) { case (0): //Crit Frame if (Mathf.Abs(((Vector2)(transform.position) - (Vector2)(other.transform.position)).magnitude) <= critRange) { if (!_audioSource.isPlaying) { _audioSource.clip = ResourceManager.GetInstance().GetAudioManager().GetAudioClip("StrongPunch"); _audioSource.Play(); TempSpriteManager.GetInstance().PlayAnimation("Large_Hit_02", other.transform.position, new Vector2(1 * Mathf.Sign(player.transform.localScale.x), 1), "Foreground2", 6); } otherObj.DealTempDamage(damage * damageMod * 2.0f); otherObj.LinearKnockback(directionVector, 0.4f); } else { if (!_audioSource.isPlaying) { _audioSource.clip = ResourceManager.GetInstance().GetAudioManager().GetAudioClip("MediumPunch"); _audioSource.Play(); TempSpriteManager.GetInstance().PlayAnimation("Mid_Hit_01", other.transform.position, new Vector2(1 * Mathf.Sign(player.transform.localScale.x), 1), "Foreground2", 6); } otherObj.DealTempDamage(damage * damageMod); otherObj.Knockback(directionVector, force, 0.2f); } break; case (1): if (!_audioSource.isPlaying) { _audioSource.clip = ResourceManager.GetInstance().GetAudioManager().GetAudioClip("MediumPunch"); _audioSource.Play(); TempSpriteManager.GetInstance().PlayAnimation("Mid_Hit_01", other.transform.position, new Vector2(1 * Mathf.Sign(player.transform.localScale.x), 1), "Foreground2", 6); } otherObj.DealTempDamage(damage * damageMod * 0.9f); otherObj.Knockback(directionVector, force, 0.15f); break; case (2): if (!_audioSource.isPlaying) { _audioSource.clip = ResourceManager.GetInstance().GetAudioManager().GetAudioClip("MediumPunch"); _audioSource.Play(); TempSpriteManager.GetInstance().PlayAnimation("Mid_Hit_01", other.transform.position, new Vector2(1 * Mathf.Sign(player.transform.localScale.x), 1), "Foreground2", 6); } otherObj.DealTempDamage(damage * damageMod * 0.8f); otherObj.Knockback(directionVector, force, 0.10f); break; case (3): if (!_audioSource.isPlaying) { _audioSource.clip = ResourceManager.GetInstance().GetAudioManager().GetAudioClip("MediumPunch"); _audioSource.Play(); TempSpriteManager.GetInstance().PlayAnimation("Mid_Hit_01", other.transform.position, new Vector2(1 * Mathf.Sign(player.transform.localScale.x), 1), "Foreground2", 6); } otherObj.DealTempDamage(damage * damageMod * 0.7f); otherObj.Knockback(directionVector, force, 0.05f); break; } }
public override void OnHit(Collider2D other) { BaseGameEntity otherObj = other.gameObject.GetComponent <BaseGameEntity>(); Vector2 directionVector = (otherObj.transform.position - transform.position).normalized + Vector3.up; float angle = Mathf.Rad2Deg * Mathf.Acos(Vector2.Dot(directionVector.normalized, Vector2.right)); switch (_animator.currAnim.currFrame) { case (0): //Crit Frame if (Mathf.Abs(((Vector2)(transform.position) - (Vector2)(other.transform.position)).magnitude) <= critRange) { if (!_audioSource.isPlaying) { _audioSource.clip = ResourceManager.GetInstance().GetAudioManager().GetAudioClip("StrongPunch"); _audioSource.Play(); TempSpriteManager.GetInstance().PlayAnimation("Large_Hit_02", other.transform.position, new Vector2(1 * Mathf.Sign(player.transform.localScale.x), 1), angle, "Foreground2", 6); } otherObj.DealTempDamage(damage * damageMod * 2.0f); otherObj.LinearKnockback(directionVector, 0.4f); } else { if (!_audioSource.isPlaying) { _audioSource.clip = ResourceManager.GetInstance().GetAudioManager().GetAudioClip("MediumPunch"); _audioSource.Play(); TempSpriteManager.GetInstance().PlayAnimation("Mid_Hit_01", other.transform.position, new Vector2(1 * Mathf.Sign(player.transform.localScale.x), 1), angle, "Foreground2", 6); } otherObj.DealTempDamage(damage * damageMod); otherObj.Knockback(directionVector, force, 0.2f); } break; case (1): if (!_audioSource.isPlaying) { _audioSource.clip = ResourceManager.GetInstance().GetAudioManager().GetAudioClip("MediumPunch"); _audioSource.Play(); TempSpriteManager.GetInstance().PlayAnimation("Mid_Hit_01", other.transform.position, new Vector2(1 * Mathf.Sign(player.transform.localScale.x), 1), angle, "Foreground2", 6); } otherObj.DealTempDamage(damage * damageMod * 0.9f); otherObj.Knockback(directionVector, force, 0.15f); break; case (2): if (!_audioSource.isPlaying) { _audioSource.clip = ResourceManager.GetInstance().GetAudioManager().GetAudioClip("MediumPunch"); _audioSource.Play(); TempSpriteManager.GetInstance().PlayAnimation("Mid_Hit_01", other.transform.position, new Vector2(1 * Mathf.Sign(player.transform.localScale.x), 1), angle, "Foreground2", 6); } otherObj.DealTempDamage(damage * damageMod * 0.8f); otherObj.Knockback(directionVector, force - 1000, 0.10f); break; case (3): if (!_audioSource.isPlaying) { _audioSource.clip = ResourceManager.GetInstance().GetAudioManager().GetAudioClip("MediumPunch"); _audioSource.Play(); TempSpriteManager.GetInstance().PlayAnimation("Mid_Hit_01", other.transform.position, new Vector2(1 * Mathf.Sign(player.transform.localScale.x), 1), angle, "Foreground2", 6); } otherObj.DealTempDamage(damage * damageMod * 0.7f); otherObj.Knockback(directionVector, force - 2000, 0.05f); break; } }
public override void OnHit(Collider2D other) { BaseGameEntity otherObj = other.gameObject.GetComponent <BaseGameEntity>(); Vector2 directionVector = (otherObj.transform.position - transform.position).normalized; Vector2 horizontalVector = Vector2.right; Vector2 knockbackVector = Quaternion.AngleAxis(-90, new Vector3(0.0f, 0.0f, 1.0f)) * directionVector; if (Mathf.Sign(transform.localScale.x) == -1.0f) { horizontalVector = Vector2.left; knockbackVector = Quaternion.AngleAxis(90, new Vector3(0.0f, 0.0f, 1.0f)) * directionVector; } //Get the angle between the vector connecting the attacker and defender //angle between vetors : cosTheta = a dot b (if normlized skip we can skip devision step) float attackAngle = Mathf.Rad2Deg * Mathf.Acos(Vector2.Dot(directionVector, horizontalVector)); //if the attack angle is within 30 degrees then its a crit if (Mathf.Abs(attackAngle) <= 40.0f) { crit = true; } else { crit = false; } switch (_animator.currAnim.currFrame) { case (0): if (crit) { otherObj.DealTempDamage(damage * damageMod * 2.0f); otherObj.LinearKnockback(knockbackVector, 0.4f); if (!_audioSource.isPlaying) { _audioSource.clip = ResourceManager.GetInstance().GetAudioManager().GetAudioClip("StrongPunch"); _audioSource.Play(); TempSpriteManager.GetInstance().PlayAnimation("Large_Hit_02", other.transform.position, new Vector2(1 * Mathf.Sign(player.transform.localScale.x), 1), attackAngle, "Foreground2", 6); } } else { otherObj.DealTempDamage(damage * damageMod); otherObj.Knockback(knockbackVector, force, 0.15f); if (!_audioSource.isPlaying) { _audioSource.clip = ResourceManager.GetInstance().GetAudioManager().GetAudioClip("MediumPunch"); _audioSource.Play(); TempSpriteManager.GetInstance().PlayAnimation("Mid_Hit_01", other.transform.position, new Vector2(1 * Mathf.Sign(player.transform.localScale.x), 1), attackAngle, "Foreground2", 6); } } break; case (1): if (crit) { otherObj.DealTempDamage(damage * damageMod * 2.0f); otherObj.LinearKnockback(knockbackVector, 0.4f); if (!_audioSource.isPlaying) { _audioSource.clip = ResourceManager.GetInstance().GetAudioManager().GetAudioClip("StrongPunch"); _audioSource.Play(); TempSpriteManager.GetInstance().PlayAnimation("Large_Hit_02", other.transform.position, new Vector2(1 * Mathf.Sign(player.transform.localScale.x), 1), attackAngle, "Foreground2", 6); } } else { otherObj.DealTempDamage(damage * damageMod); otherObj.Knockback(knockbackVector, force, 0.15f); if (!_audioSource.isPlaying) { _audioSource.clip = ResourceManager.GetInstance().GetAudioManager().GetAudioClip("MediumPunch"); _audioSource.Play(); TempSpriteManager.GetInstance().PlayAnimation("Mid_Hit_01", other.transform.position, new Vector2(1 * Mathf.Sign(player.transform.localScale.x), 1), attackAngle, "Foreground2", 6); } } break; case (2): otherObj.DealTempDamage(damage * damageMod); otherObj.Knockback(knockbackVector, force, 0.05f); if (!_audioSource.isPlaying) { _audioSource.clip = ResourceManager.GetInstance().GetAudioManager().GetAudioClip("WeakKick"); _audioSource.Play(); TempSpriteManager.GetInstance().PlayAnimation("Mid_Hit_01", other.transform.position, new Vector2(1 * Mathf.Sign(player.transform.localScale.x), 1), attackAngle, "Foreground2", 6); } break; } }