- Home /
How to create destructible tile based 2D terrain like 'Broforce' does ?
There seems to be a particular number of bullets(damage) that each tile can take before being destroyed. There also is a blast radius of the bomb that destroys all the tiles in its' vicinity. What aspects of Unity do I need to look into, to achieve such destructible and crumbling effects ?
Answer by error031 · Aug 18, 2014 at 09:28 PM
I think you should make script and attach to tiles that holds number of times you shooted at that tile. Something like:
tileLogic.js
 var tileHealth : int;
 
 function Start() {
    tileHealth = 3; 
 }
 
 function Update () {
    if(tileHealth == 0){
       Destroy (gameObject); 
    }
 }
 
 function OnCollisionEnter2D(coll: Collision2D) {
     if (coll.gameObject.tag == "Bullet")
         tileHealth--;
     if (coll.gameObject.tag == "Bullet")
         tileHealth-=3;
 
 }
In this case you should have colliders2d on tile, bullet and bomb (size of the radius).
Answer by Cherno · Aug 18, 2014 at 10:31 PM
You declare a 2-dimensional array which holds the integrity values of each block.
 var world : float[,] = new float[worldSizeX, worldSizeY];
If a tile gets damages, you just decrease the float value at the coordinates.
 world[2,6] -= damage;
 if(world[2,6] <= 0.0f) {
      //some kind of destruction effect?
 }
Getting all tiles in a radius should be easy, just use a nested loop with x - 1 to x + 1 and so on.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                