Improve body combine algorithm
englercj opened this issue · comments
When converting a tilemap layer into physics bodies the current algorithm will combine adjacent bodies on an X axis, resulting in bodies which is less than one-per-tile but still can present problems with performance or edge sticking (by stacking strips).
This algorithm should really combine all adjacent bodies into a single polygon.
Hey I made my own kind of version recently and while it's not perfect, it works alright. Result is here: http://jimvliet.github.io/HTML5-Game/objectConverter
The code is in this file: https://github.com/JimVliet/HTML5-Game/blob/master/scripts/functionFile.ts
It works like this: It starts at the top left and goes to the bottom right. Everytime it finds a solid object which isn't already used it will create a rectangle with the largest possible area from that position. Then the tiles used in that rectangle won't be able to be used again.
If you have any questions, feel free to ask.
EDIT: This is my current game: http://jimvliet.github.io/HTML5-Game/ in which this is used