0

The image attached is a mask of "walkable space" for a game, which is painted by the player, and so could be anything. I need to create colliders that prevent the player from walking on to the blue parts of the mask (water). The game itself is in 3D space, the mask is for the terrain textures (Unreal Engine 4).

What I've done at the moment is reduce the size of the texture from 2048x2048 to 256x256 and I create a collider in 3D space for each blue pixel in the mask. This works ok with small amounts of blue pixels, but it's not going to work well/at all, if there's a lot of blue pixels (water). There'd be too many colliders to spawn on the fly.

And so I guess the only other option is to find points that make up the boundaries of any number concave shapes in the image. With which I will create wall colliders.

Hope that makes sense. Any help is very much appreciated.

Thanksenter image description here

Dann
  • 323
  • 5
  • 17

1 Answers1

1

After you have reduced the size to something smaller, fill a bool array with zeroes and ones, ones where there is blue, and zeroes, where there isn't. From there you can turn all ones with no zero neighbours to zeros. That is because if a cell has no empty neighbours and it isn't empty itself, no object could collide with it and you don't need to check. That should vastly improve performance, but if you need more, you can then find all straight lines of filled cells and check for collisions with those. So it would look something like this:

enter image description here

In this case you end up having to check collisions with 6 objects instead of with 18 and the difference gets greater as the blobs get bigger.

indjev99
  • 134
  • 1
  • 13