- Home /
Collider that can perfectly fit the shape of a sprite?
I'm trying to create the collision for one of my maps. However, I've looked online for the last hour and found nothing to answer my problem. I'm creating a tile-based game, and I want perfect collision on this sprite for one of my maps. However, I don't want to create 26 different children with box colliders to make it up. When the maps get bigger and more complicated, this will take up too much time.
I want collision to occur on the red without creating a ton of colliders, but none of the colliders seem to have the kind of collision I'm looking for. I've tried the polygon collider, but due to the split-up nature of the sprite it's impossible to work with. Is there something that will allow me to easily create a collider that fits the shape perfectly?
Answer by Mr_Teels · Nov 28, 2018 at 08:53 PM
Make the Red Line a Single Image. Without Floors, Walls, Etc. That is your "Collider Map". Sort it with the Sprite Layers "under" the Level and add a "Mesh Collider. Everything in the Image that has Color Information (not Alpha Channel) will be as Collider. Supported files are .png and .tiff
I have the red area as its own image. However, the mesh collider seems to only work with 3D shapes. When I try to add it, it says there's a conflict with the sprite renderer, and if I remove that to add it, the mesh collider requires a mesh filter, which only uses 3D shapes.
You can use a 'polygon collider 2d' for 2d objects.
Answer by AdamBebkoSL · May 26 at 08:28 PM
You can make a tile that represents a wall, and this tile can be given a box collider for all instances of the tile. Then you don't have to worry about doing anything manually. If you put the tile in, the collider will just work
https://docs.unity3d.com/Manual/class-TilemapCollider2D.html