Hello Guest

Author Topic: Trying to use Polygon Collider instead Edge Collider with tiles  (Read 5958 times)

akumagouki

  • Newbie
  • *
  • Posts: 6
    • View Profile
Trying to use Polygon Collider instead Edge Collider with tiles
« on: November 10, 2014, 08:24:50 pm »
Hi
I'm using 2dtoolkit to make a tiled based game, I tried to use this tutorial http://www.unikronsoftware.com/2dtoolkit/doc/2.4/tutorial/creating_polygon_colliders.html

And it works however it creates an Edge Collider, is it possible to create a Polygon Collider instead? Because the Edge Collider doesn't work for what I'm trying to do

Best!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Trying to use Polygon Collider instead Edge Collider with tiles
« Reply #1 on: November 11, 2014, 06:24:41 pm »
The tilemap creates edge colliders because unity can't deal with complex poly colliders and #2 it MUST be closed, both of which we can't ensure in tk2d (you can create open polygon shapes). You do have the code though, so you can change it to a polygon collider to see if it works in your use case.

dotty

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 65
    • View Profile
Re: Trying to use Polygon Collider instead Edge Collider with tiles
« Reply #2 on: December 08, 2014, 03:04:35 pm »
The code is actually very simple,  the file that need to amend is tk2dTileMapColliderBuilder2D.cs. Take a look at https://gist.github.com/kevdotbadger/fd2216c497495de5980d

Basically the BuildLocalMeshForChunk() method is responsible for making the edge collider, it has a bunch of if statements looking for collider types (spriteData.colliderType == tk2dSpriteDefinition.ColliderType.Box), in that branch is where you want to create the box colliders (instead of, or as well as the edge colliders).

My solution was to create (or empty) a parent game object every time the "commit" button was pressed (this is in the Build() method). Then add a shit load of box colliders into position (making the box colliders a child of the parent object - just to keep my level a little tidier). On line 195 is where the box colliders are made, inside the BuildLocalMeshForChunk() method.

Compare the original tk2dTileMapColliderBuilder2D.cs and my amended one at https://gist.github.com/kevdotbadger/fd2216c497495de5980d to see what's going on.