#Not able to blast tiles in bomb blast

1 messages · Page 1 of 1 (latest)

mighty jolt
#

hi all , I am trying to make a game where when I place a bomb on one tile, that and tiles in 3X3 areas too get destroyed. I have manage to blast bomb after 3 secs but not able to blast off tiles. I have used Coroutine but didn't work, any other method I can use?

sonic widget
mighty jolt
#

No, i have placed individual floor to make complete ground. Actually i used Raycast to identify collider and demolish in the region

#

CODE

#

private IEnumerator FloorExplosion(Vector3 direction)
{
for (int i = 0; i < 2; i++)
{
RaycastHit hit;

        Physics.Raycast(transform.position + new Vector3(0,1f,0), 2*direction, out hit,i, Wall); 

        
        if (!hit.collider) 
        {
            Debug.Log("Safe");                                      
        } 
        else 
        {
            floors = GameObject.FindGameObjectsWithTag("Destructable") ;

            foreach(var floor in floors)
            {
                floorInstance.DestroyFloor(floor);
            } 
        }

        yield return new WaitForSeconds(.05f); 
    }

}
neon ridge
#

if you're using a tile map you need a reference to the grid and the tilemap

#

get the bomb position and use the grid to convert it to a cell position

#

use that cell position on the tilemap to set the tile on the position to the destroyed tile, or set it to null if you want to delete it via the function m_Tilemap.SetTile('destroyed tile/null')

#

and do the same thing for all the tiles around it but adding the index to the bomb cell position like

Vector3Int top = cellPosition.y + 1;
Vector3Int bottom = cellPosition.y - 1;
Vector3Int topLeft = cellPosition + new Vector3Int(1, 1, 0);
etc...
mighty jolt
#

okay, i have never used tilemap, can you tell me more on it

neon ridge
#

You can watch the brackeys video on it, it covers all the needed information, except the use in runtime which is what I explained here