Hello Guest

Author Topic: Use BoxCollider2D on TileMaps instead of EdgeCollider2D  (Read 5057 times)

BlueLemming

  • Newbie
  • *
  • Posts: 3
    • View Profile
Use BoxCollider2D on TileMaps instead of EdgeCollider2D
« on: April 15, 2015, 05:03:48 am »
I'm fairly new to Unity and 2D Toolkit, so bear with me, but I'm having some huge issues with the EdgeCollider2D that the TileMap automatically generates for my 2D platformer.

I'm trying to code my "own" collision system using Raycasts because I don't want to use any Box2D Physics and Physics2D.OverlapCircle/OverlapPoint doesn't work on EdgeColliders. I'm trying to stop my player from falling when he hits the ground. So my Raycast detects I've collided with the EdgeCollider 1 pixel below me, sweet! but if I'm falling fast enough that it doesn't catch that edge of the edgecollider, then I'll fall inside the tile and it will never register the collision.

So I thought why not just use BoxCollider2D for my 32x32 tiles? It would make collisions so much easier but I can not for the life of me figure out how to tell TK2D to generate boxes instead of edges. I've tried changing the colliders in my SpriteCollection to every different kind, and it still makes edge colliders. I found a script that can generate it for me here (https://github.com/kevdotbadger/BoxColliderGenerator) but unfortunately it doesn't seem to work with Unity 5.

I'm in a bit of a rut, I'm hoping I can find some help here. If I'm unable to use box colliders, how do you guys suggest I go about coding a simple collision system without Box2D physics?

radu

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 67
    • View Profile
Re: Use BoxCollider2D on TileMaps instead of EdgeCollider2D
« Reply #1 on: April 15, 2015, 04:38:01 pm »
If you search the forums, I posted something a while back that allows you to convert edge colliders to polygon colliders. You can maybe adapt that code if you really need box colliders, but you may be able to get away with using polygon colliders.