🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Daily update #2 - Bombs

Published August 03, 2018
Advertisement

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);
		}
	}
}

 

0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement