Today I've worked on adding bombs to the game.
They are really useful for dispersing enemies and such.
The model was made a while back. It was just a mater of importing it in Unity and coding the script.
Here's a nice video I've made just for that:
There's nothing really special here, just polymorphism, Unity Components and C# delegates....
Collider[] cols = Physics.OverlapSphere(explosionCenter, m_explosionRadius, LayerMask.GetMask("Obstacles", "Entity", "Player Body", "Pickable"), QueryTriggerInteraction.Ignore);
for (int i = 0, length = cols.Length; i < length; ++i)
{
GameObject collidedObject = cols[i].gameObject;
HealthController healthController;
Rigidbody rigidbody;
AbstractExplosionActionable explosionActionable;
if(collidedObject.layer == LayerMask.NameToLayer("Entity") || collidedObject.CompareTag("Player")){
healthController = collidedObject.GetComponent<HealthController>();
healthController.RawHurt(m_explosionDamage, transform);
} else if(collidedObject.layer == LayerMask.NameToLayer("Pickable")) {
rigidbody = collidedObject.GetComponent<Rigidbody>();
if (rigidbody != null && !rigidbody.isKinematic) {
rigidbody.AddExplosionForce(m_explosionDamage, transform.position, m_explosionRadius);
}
} else if (collidedObject.layer == LayerMask.NameToLayer("Obstacles")) {
explosionActionable = collidedObject.GetComponent<AbstractExplosionActionable>();
if (explosionActionable != null) {
explosionActionable.action.Invoke(m_explosionDamage, m_explosionRadius, explosionCenter);
}
}
}