As you can see in that video I am having really weird behavior when I use tilemaps in matter.js, for example when the ball bounces off of the platform initially it should bounce directly upward since the platform is completely flat but it bounces to the left, and when the character moves they keep “bouncing” off of the tiles even though they are on the ground. As you can see I tried to chamfer the player so prevent getting caught on the tiles but it didn’t really help. I noticed that in the matterjs examples they use really big tiles to prevent this behavior but that won’t work with my game, is there any way to fix this?
Hi @anthonydibi ,
Have you solved the issue?
If not, I’ll tidy up my solution to share it (I faced the same and reproduced it in a breakout sandbox: video).
It all boils down to the ball hitting tile corners. I’ve tried all sorts of tweaks like fiddling with pre&post-collision data like normal, home-made expected trajectory computing, etc.
Appart from interfering with Matter’s internals and fixing some of the behaviors, that wasn’t the right path.
The best way I found was to iterate over the static tiles from Tiled (marked with a specific collision property) and create islands (groups of contiguous tiles). Doing so requires listing vertices to create the shape’s envelope.
My solution isn’t perfect (yet?) as I still have to deal with specific cases like these:
- my Tiled level is closed by a full border of tiles, I need the script the “close” the shape by adding a perpendicular vertex to avoid infinite looping.
My Solution however already deals with situations like:
- my Tiled tileset has some specific tile properties (snow, metal, sand, mud) to affect collision sounds, restitution (bounce), friction & co. and I need a way to “enrich” the resulting tiles.
Let me know if you wish to see that code with a quick walkthrough and I’ll gladly prepare that.
Hi again,
I cleaned up the code and got my sandbox uploaded.
See the problem, same as yours - then the solution (islanding). Works perfectly here, I think it’ll help with your issue:
You can test it online (use left/right keys to switch between problem & solution):
https://www.dercetech.com/test/phaser-matter-sandbox/v2.0.0/?level=0
The islanding script to import in your project:
And the usage example:
Let me know what you think!