Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

2D Top Down Destructible TileMap

Discussion in '2D' started by PaRsOnIsPhErE, Jun 25, 2020.

  1. PaRsOnIsPhErE

    PaRsOnIsPhErE

    Joined:
    Dec 19, 2018
    Posts:
    19
    Hi guys,

    Looking for advice on where I need too be looking, and what systems etc I need to be researching to achieve what i'm looking for. Just a quick thanks in advance.

    So I currently have my levels built using tilemaps, 32px by 32px in size (so tiny) and composite colliders. I've decided now that when a players projectile hits a wall, instead of just a particle effect, I would also like some of the wall too be chipped away. Only a few pixels at a time. Please see below image for what the levels look like.

    https://i.ibb.co/jrTJDgY/Destructable-Walls.png

    Now I don't want all the walls too be damaged. The outer walls on the edges to be exact. So for this I assume I would create 2 Tilemaps, and only have the damage code affect one??

    Now I've come from game maker and previously I would have created a new layer with a circle sprite for instance on it, and then removed that circle shape from the pixels on the same layer as the walls. Surely there is an easier way in Unity?? The walls are only 32px by 32px and the projectile is 2px by 6px I think... so tiny artwork.

    Could anyone point me in the direction of an article, or the name of an algorithm or system, as I only seem to be able to find demo's, and nothing to help me drive this forward.

    Thanks all!
     
  2. PaRsOnIsPhErE

    PaRsOnIsPhErE

    Joined:
    Dec 19, 2018
    Posts:
    19
    Hey guys,

    So I have part of my idea sorted. As seen in the first image below, i'm using sprite masks to remove sections of the tilemap. The issue now is colliders... i'm running a composite collider on my tilemap, and am wandering if there's a way to refresh it??

    https://i.ibb.co/k9yxTqj/Sprite-Mask-Collider.png

    The other issue I have come across, is every time a projectile hits the wall, it instantiate's a sprite mask object... which in turn leads my hierachy to look like the below image with 'too many' mask objects... Would there be a better solution to this??

    https://i.ibb.co/vcc4np1/Sprite-Mask-Many.png

    Thanks all, appreciate any comments, replies!