private void OnTriggerEnter(Collider collision) { // HitLogic LaserBulletScript laserBullet = collision.gameObject.GetComponent <LaserBulletScript>(); ShotgunBulletScript shotgunBullet = collision.gameObject.GetComponent <ShotgunBulletScript>(); BulletScript normalBullet = collision.gameObject.GetComponent <BulletScript>(); // Convert BoundsToLocalSpace Vector3 collisionPoint = collision.ClosestPoint(transform.position); Vector3 collisionNormal = transform.InverseTransformDirection(collisionPoint - transform.position).normalized; if (!is3D) { // Convert to 2D tangent system collisionNormal = new Vector3(collisionNormal.x, 0f, collisionNormal.z); } // Check if the shot is from the front within a threshold 1.7f is north east to north west if (laserBullet != null && laserBullet.isEnemyShot) { if (isShielding && !IsFrontShot(collision.transform)) { // Calculate Normal Differently for laser beam collisionNormal = transform.InverseTransformDirection(selfCollider.ClosestPoint(collision.transform.position) - transform.position).normalized; // Spawn Effect and set its parent as ship gameManager.BeginEffect(GameConstants.EffectTypes.ShieldHit, collisionPoint, collisionNormal).transform.SetParent(transform); adaptiveShield.OnHit(collisionNormal, laserBullet.damage); laserBullet.OnShieldEnter(transform.TransformDirection(collisionNormal), collision.ClosestPoint(transform.position)); PlaySound(hitShieldSound); } else { // Get Effect for laser on initial shot gameManager.BeginEffect(GameConstants.EffectTypes.BulletHit, collisionPoint, collisionNormal).transform.SetParent(transform); TakeDamage(laserBullet.damage); laserBullet.OnHit(); PlaySound(hitPlayerSound); } } else if (shotgunBullet != null && shotgunBullet.isEnemyShot) { if (isShielding && !IsFrontShot(collision.transform)) { adaptiveShield.OnHit(collisionNormal, shotgunBullet.damage); gameManager.BeginEffect(GameConstants.EffectTypes.ShieldHit, collisionPoint, collisionNormal).transform.SetParent(transform); shotgunBullet.OnShield(transform.TransformDirection(collisionNormal)); PlaySound(hitShieldSound); } else { TakeDamage(shotgunBullet.damage); gameManager.BeginEffect(GameConstants.EffectTypes.BulletHit, collisionPoint, collisionNormal).transform.SetParent(transform); shotgunBullet.OnHit(); PlaySound(hitPlayerSound); } } else if (normalBullet != null && normalBullet.isEnemyShot) { if (isShielding && !IsFrontShot(collision.transform)) { adaptiveShield.OnHit(collisionNormal, normalBullet.damage); gameManager.BeginEffect(GameConstants.EffectTypes.ShieldHit, collisionPoint, collisionNormal).transform.SetParent(transform); normalBullet.OnShield(transform.TransformDirection(collisionNormal)); PlaySound(hitShieldSound); } else { TakeDamage(normalBullet.damage); gameManager.BeginEffect(GameConstants.EffectTypes.BulletHit, collisionPoint, collisionNormal).transform.SetParent(transform); normalBullet.OnHit(); PlaySound(hitPlayerSound); } } }