I have a construct in my game that consists of a group of GameObjects like this:
Ship (Convex Mesh Collider / Rigid Body)
Shield Parent
Shield Emitter Element (Box Colliders)
... (Multiple Emitters)
The Ship and the Shield Emitter Elements both make use of a script component that is designed to handle collisions and track damage to the GameObject they are attached to.
The problem is that when something collides with the ShieldEmitterElement, the collision event gets called on Ship instead and I have no idea why. I’ve checked the bounds of the colliders for both items, and the Ship collider is definitely NOT extending out past the Shield Emitter Element, but it is definitively calling the script on the Ship, and the damage is being applied there.
This is the method in question:
public virtual void OnCollisionEnter(Collision collision) {
if (collision.gameObject.tag == "Dust") {
return;
}
DamagePacket Damage = new DamagePacket();
if (collision.gameObject.tag == "WeaponProjectile") {
DamageSource projectile = collision.gameObject.GetComponent<DamageSource>();
if (projectile.OriginShip == gameObject) {
return;
}
Damage = projectile.CalculateDamage();
Instantiate(projectile.impactParticles, collision.transform.position, Quaternion.Inverse(collision.transform.rotation));
Destroy(collision.gameObject);
} else {
if (collision.gameObject.GetComponent<Destructable>() != null) {
//Rigidbody otherRB = collision.rigidbody;
Damage = collision.gameObject.GetComponent<Destructable>().CollisionDamage(RigidBody.mass, collision.relativeVelocity.magnitude);
}
}
TakeDamage(Damage);
}