RigidBody2d bounces on tiles in the wrong direction

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Milan

So I have this bouncing ball which is a rigidbody2d with the bounce property in the physics material set to 0.6, and a tileset with collision set up. The issue is that sometimes when it bounces off from the ground it goes in the wrong direction, see at the end of this video. This only happens with tiles, I tested with a static body as the floor, and it worked just fine. I assume that this is because each tile has its own collision shape and when it bounces close to where two tiles meet it bounces from the side or from the corner of a tile.

Anyone has an idea how to fix this?

:bust_in_silhouette: Reply From: Milan

So I figured it out myself after a bit, but here is the solution for everyone reading this in the future. So the issue was indeed caused by the tiles collisions being separate, and to solve this I used this little script made by Ratty. It combines the collision shapes into one single polygon and passes it to a StaticBody2d, just be sure to disable the TileMap’s collision.

I don’t suppose you’ve still got this script? The links you provided are no longer working and I’ve been trying to figure this out for weeks!

Lumsdinho | 2023-03-23 10:15

The links are indeed unavailable. But I found the script in my game that does the fix. As I mentioned, it merges the collision shapes together. Here is the script that does the merging logic, and here is the one that uses that script to actually do the merging on a specific tileset. I don’t remember exactly how it works as I made this project 2 years ago, but it’s a good starting point. You can check out the full source code, my game is open source.

Milan | 2023-03-23 18:21