private void OnTriggerEnter2D(Collider2D hit) { //Debug.Log("HIT " + hit.gameObject.tag); if (hit.gameObject.CompareTag("Environment")) //If projectile collides with environement { //Debug.Log("Destroy"); Destroy(this.gameObject); } else if (isEnemyProjectile && hit.gameObject.CompareTag("Player")) { Debug.Log("Should damage player"); Destroy(this.gameObject); } else if (!isEnemyProjectile && hit.gameObject.CompareTag("EnemyHitbox")) { HitBox hitBox = hit.gameObject.GetComponent <HitBox>(); if (hitBox) { hitBox.ApplyDamage(damage); Destroy(this.gameObject); } } }
void HeAmmoOnHit() { if (IsHitted) { return; } RaycastHit Rayhit; if (RayHitDetect(out Rayhit)) { float Degree = Vector3.Angle(transform.forward * -1, Rayhit.normal * 1); int Penetration = Mathf.RoundToInt(Random.Range(0.85f, 1.25f) * HePenetration * EnergyDamper); int Damage = Mathf.RoundToInt(Random.Range(0.85f, 1.25f) * HeDamage * EnergyDamper); if (Rayhit.collider.GetComponent <TerrainManager>()) { Rayhit.collider.GetComponent <TerrainManager>().DestroyTerrain(Rayhit.point, Mathf.Clamp(HeRange, 0, 5)); } if (Rayhit.collider.transform.parent.parent.GetComponent <Building>() != null) { Rayhit.collider.transform.parent.parent.GetComponent <Building>().ApplyAmmoHit(HeDamage); } if (Rayhit.collider.gameObject.layer == LayerMask.NameToLayer("HitBox")) { HitBox _hitBox = Rayhit.collider.GetComponent <HitBox>(); if (_hitBox == null) { return; } _hitBox.ApplyDamage(Penetration, Damage, Degree, fireOwner, bulletType, fireStartPosition, Rayhit.point, Caliber); CreateFireExplosionHitOnArmor(Rayhit.point, Rayhit.normal, FireExplosionHitOnArmor); } else { CreateFireExplosionHitOnArmor(Rayhit.point, Rayhit.normal, FireExplosionHitOnGround); RaycastHit[] HEAttachedHits = Physics.SphereCastAll(Rayhit.point, HeRange, transform.forward, HeRange, 1 << LayerMask.NameToLayer("HitBox")); System.Collections.Generic.List <Transform> Attached = new System.Collections.Generic.List <Transform>(); foreach (RaycastHit HEAttachedHit in HEAttachedHits) { if (!Attached.Contains(HEAttachedHit.collider.transform.root)) { HitBox _hitBox = HEAttachedHit.collider.GetComponent <HitBox>(); if (_hitBox == null) { continue; } float Distance = (Rayhit.point - HEAttachedHit.collider.transform.position).magnitude; float HEWithDistanceDamage = Damage; HEWithDistanceDamage *= Mathf.Clamp(1f - (Distance / HeRange), 0f, 1f); _hitBox.ApplyDamage(Penetration, Mathf.RoundToInt(HEWithDistanceDamage), Degree, fireOwner, bulletType, fireStartPosition, HEAttachedHit.point, Caliber); Attached.Add(HEAttachedHit.collider.transform.root); } } } IsHitted = true; Explode(); } }
void APAmmoOnHit() { RaycastHit hit; if (IsHitted) { return; } if (RayHitDetect(out hit)) { float Degree = Vector3.Angle(transform.forward * -1, hit.normal * 1); //Normalize Degree = Mathf.Clamp(Degree, 0, Degree - shellNormalizationAngle - (float)Caliber / 100); int Penetration = 0; switch (bulletType) { case BulletType.ApAmmo: Penetration = APPenetration; PenetrationDamper *= 1.2f; break; case BulletType.APCRAmmo: Penetration = ApcrPenration; PenetrationDamper *= 2; break; } float Distance = Vector3.Distance(transform.position, P0); Penetration = Mathf.RoundToInt(Random.Range(0.95f, 1.05f) * Penetration * EnergyDamper - Distance * 0.1f * PenetrationDamper); int Damage = Mathf.RoundToInt(Random.Range(0.95f, 1.05f) * APDamage * EnergyDamper); if (hit.collider.gameObject.layer == LayerMask.NameToLayer("HitBox")) { HitBox _hitBox = hit.collider.GetComponent <HitBox>(); if (_hitBox == null) { return; } if (Degree > 65) { transform.position = hit.point; transform.LookAt(Vector3.Reflect(transform.forward * 1, hit.normal) + hit.point); EnergyDamper *= 0.4f; _hitBox.ApplyRicochet(fireOwner); Debug.DrawRay(transform.position, hit.normal); if (!GameDataManager.OfflineMode) { CreateFireExplosionHitOnArmor(hit.point, transform.forward, "BulletReflectionEffect"); } return; } _hitBox.ApplyDamage(Penetration, Damage, Degree, fireOwner, bulletType, fireStartPosition, hit.point, Caliber); CreateFireExplosionHitOnArmor(hit.point, hit.normal, FireExplosionHitOnArmor); } else if (hit.collider.gameObject.layer == LayerMask.NameToLayer("Terrian")) { CreateFireExplosionHitOnArmor(hit.point, hit.normal, FireExplosionHitOnGround); if (!isMachineAmmo) { hit.collider.GetComponent <TerrainManager>().DestroyTerrain(hit.point, 2); } } else { CreateFireExplosionHitOnArmor(hit.point, hit.normal, FireExplosionHitOnGround); if (hit.collider.transform.GetComponentInParent <Building>() != null) { hit.collider.transform.GetComponentInParent <Building>().ApplyAmmoHit(APDamage); } } IsHitted = true; if (!isMachineAmmo) { PoolManagerSpawnModule.CreateObject(ammoAudio.ammoExplAudio.ToString(), transform.position, transform.eulerAngles); } Explode(); } }