Generate collider for 2D mesh with odd shaped tiles at run time

Note: I put a thread up with the same name last week but realized that my problem isn’t actually solved because I need a collider that wraps around the graphic “content” rather than the square tiles themselves.

I have been working on my own engine for building 2D levels. You pass it a List of tiles and a tileset and it builds meshes at run time with triangles supporting the tiles from the tileset. The tiles would naturally be square, but if I want a slope or an irregular shaped tile I would need the collider to repressent that also.

I am wondering if there is a way to wrap a 2D collider around the mesh texture (rather than the triangles themselves). I have searched high and low but maybe I am not searching for the correct thing? Any help would be greatly appreciated.

A final point, if there is another way to achieve this kind of collision I would be happy to hear it! :slight_smile:

if you give all your meshes line colliders, then when it builds the meshes, it could take all these line colliders and merge them in to a polygon.

All you are doing is transposing an array of vector2 points, so if the mesh textures are irregular shapes you can use 3d colliders then just drop the Z in your conversion

Vector3 myVec3 = new Vector3(0,0,0);

print((Vector2)myVec3);

Should print a vector2