Hello Guest

Author Topic: Best Practice for destructible tilemaps?  (Read 3829 times)

Doghelmer

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
Best Practice for destructible tilemaps?
« on: September 18, 2014, 10:53:02 am »
I’m currently developing a top-down game where wall tiles are frequently destroyed, and the map size is fairly large (around 160x160 tiles).  I haven’t dived too far into tilemap creation yet, but given that destructibility is a super-important aspect of my game, I’m wondering what the most efficient way to accomplish this would be.

Would I want to use colliders on the tilemap tiles, or would this be a bad idea if I’m going to be frequently rebuilding the tilemap?

If it’s OK to do things this way, what is the best way of checking for collision between a bullet sprite and one of the individual tiles?

If it’s not a good idea to use colliders, would perhaps a better solution be to dynamically position a bunch of box collider GameObjects to match up with the tilemap in the area directly surrounding the player?  Or is there a more common solution?
« Last Edit: September 18, 2014, 11:09:41 am by Doghelmer »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Best Practice for destructible tilemaps?
« Reply #1 on: September 19, 2014, 02:56:58 pm »
Rebuilding colliders at runtime is impractical. Box colliders will work, especially if you can constrain them around the player.

You can rebuild the render meshes at runtime, and only affected chunks are rebuilt when you call tilemap.Build(). The partition size controls the granularity of this, you certainly have room to optimize this depending on your needs.