Hello Guest

Author Topic: Tilemap collider caps...?  (Read 4267 times)

Bracco

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Tilemap collider caps...?
« on: August 03, 2013, 06:17:50 pm »
hi there, i'm quite new to Unity and 2DTk so it took me a while to figure out that the odd behaviour i was getting out of triggers was due to missing front/back caps on my tilemap collider.

for now, i just put the tiles on polygon collider which has the option to have caps but... doesn't really seem an optimal choice to me. is there any other way, or perhaps could caps for box colliders in tilemap be implemented in next version?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Tilemap collider caps...?
« Reply #1 on: August 03, 2013, 07:26:11 pm »
Is there any particular reason you need front and back caps on tilemaps? Due to the large number of triangles, this could end up being incredibly costly. I recommend not doing it unless absolutely necessary.

Edit: I was thinking of removing support for caps altogether in the next collision system update.
« Last Edit: August 03, 2013, 07:34:25 pm by unikronsoftware »

Bracco

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Tilemap collider caps...?
« Reply #2 on: August 04, 2013, 10:22:51 am »
actually yes, i need it for my project.

i have the player moving around objects in the scene with a snap-to-grid mechanism, and using trigger colliders to determine if the object the player is trying to place has room there or not

without caps, my player could place objects inside the tilemap stuff, which is not what i want

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Tilemap collider caps...?
« Reply #3 on: August 04, 2013, 11:52:47 am »
You can enable caps for box colliders by changing a line in tk2dTileMapColliderBuilder -

from:
Code: [Select]
int[] indicesFwd = { 2, 1, 0, 3, 1, 2, 4, 5, 6, 6, 5, 7, 6, 7, 3, 6, 3, 2, 1, 5, 4, 0, 1, 4 };
to:
Code: [Select]
int[] indicesFwd = { 2, 1, 0, 3, 1, 2, 4, 5, 6, 6, 5, 7, 6, 7, 3, 6, 3, 2, 1, 5, 4, 0, 1, 4, 0, 4, 6, 2, 0, 6, 3, 7, 1, 1, 7, 5 };

But there might be a better way of doing this - since they're box colliders anyway, you could probably use:
GetTileIdAtPosition( ... )
and GetTileInfoForTileId( ... )
All you need to do is store some identifying data in the data tab - eg. 1 in int value to identify solid tiles, and you can work out if a tile is solid or not. Much much more efficient than collider caps, esp so in terms of number of collider polys.