I’m here to ask for help because I’m struggling on something that may be easy for many of you.
I want to give the opportunity to import our own map in the game as a PNG image.
Then I would like to convert it to a playable terrain by just applying it to a cube (this part is ok).
And i need to generate a dynamic mesh collider that correspond to the visible part of the image, to allow a player going trough theses spaces.
Do you have any clues on how I can achieve this, while still using the internal physics system ?
Well, a PNG only has colour information, so on its own isn’t going to do the trick. You’re going to either have to make an assumption about what colours represent collision area, or you’re going to have to supply additional data somehow, or you’re going to have to rely on edge detection filters or similar. Without knowing the type of image you wish to use we really can’t help there.
Anyway, from there you’ll need to do some image processing to identify in image space the collidable areas. Then convert those to 3D and use them to construct colliders. Again, without knowing what kind of map we’re talking about, it’s hard to give advice. You could trace edges and extrude to create mesh colliders, or you could fill areas with primitives. Either way there are algorithms that will help.
I’m not really sure where to start.
All I have now, is a plane with a mesh collider.
I added a material with an unlit transparent shader and the map is the texture.
If I analyze my map, pixel by pixel and store in bi-dimensional array, if a pixel is collidable or not, from this grid, will it be possible to generate a mesh collider ?
This is what I need, certainly, but I would like to achieve the same kind of result with help and searching, instead of paying for this (but it looks great, I don’t deny it !).
Then you should expect to spend a lot of time learning the algorithm behind such a technique, and then a lot of time actually implementing it. I haven’t used that asset yet, but the video is practically magic.
As i’m making a 2d game, what I could do is scan for each pixel of my map and store playable pix in an array.
Then as 1 unit = 1 pixel, I could create a cube on each playable pixel for the collision.
Then after that I guess it will be okay, but very heavy to load. It will need optimization.
You’re heading in the right direction here. Since it’s cubes, you could probably optimise ~80% of them out by finding fully covered areas and replacing them with a single larger cube. There are algorithms for this which you should be able to find with a bit of a search, too.