Posts

Showing posts from September, 2017

How to do chain damage in a Unity 3D game using C#

Chain damage is used in many video games as the second stage or upgrade to an existing damage from a weapon/spell. The concept is simple, one enemy is targeted and receives most of the damage and surrounding enemies receives some damage as well. This article will show you a few ways to create this in Unity 3d.
General idea: At the initial target a sphere of X radius is created and all the assets within that radius are added to a list and damaged accordingly.
The set up: A method is called when damage needs to be applied. That then creates a physics.overlapcircle with X radius at the target position. This gets an array of all the colliders in that radius and can apply damage accordingly. An example method s is below. public void ChainDamage(Vector3 center, float radius, int enemyCount, int damageAmount, int degradeAmount) { Collider[] allColliders = Physics.OverlapSphere(center, radius); // the first item in the array is your main target the next item in the array is the next c…