2
\$\begingroup\$

This is in regards to something like a sidescroller where you have a tiled map where each tile uses a 2d box collider.

If you use a 2d circular collider as an example for your character, as it rolls across a series of tiled 2d box colliders, it will occasionally collide with the seams between tiles rather than rolling smoothly across them.

In my scenario here, the tiles are 1x1 units snapped directly adjacent to each other. When rolling a 2d circular collider across a row of tiles, it goes mostly smooth but the more force applied, the greater chance of the circle flying up into the air rather than it's y staying the same as it rolls across them.

The obvious conclusion I had was to use edge colliders instead which works fine, but I'm hoping to find a way to completely eliminate this problem even with just 2d box colliders.

Thanks, Tim

\$\endgroup\$

2 Answers 2

2
\$\begingroup\$

Edge colliders are likely to have better performance characteristics for this type of situation, since this is exactly the type of use case they were meant for.

That said, if you want to do it with box colliders, you can have a script that simplifies the world collision representation by grouping adjacent boxes. Say after scanning the tiles in your level it detects 5 identical floor tiles in a row; it could delete those 5 colliders and create a new, larger box collider that occupies the same space. Then there are no seams within that 5-tile span (and fewer collision objects to check - bonus!)

This could be done as an offline process via an Editor script (though this may interfere with subsequent editing of the level), or as a runtime preprocessing step when the level is loaded (which may delay the loading somewhat, but profile to see if it's noticeable).

\$\endgroup\$
2
  • \$\begingroup\$ That's all I could come up with as well, but after tiling edge colliders next to each other, I noticed they could cause the exact same effects as the box colliders so instead I've went with the second part of your suggestion which did take some time to script.. but I think is very worth it. \$\endgroup\$
    – Mythics
    Commented Feb 10, 2015 at 16:36
  • \$\begingroup\$ To clarify: the way to use edge colliders is not to tile them side-by-side, it's to have one edge collider that represents all edges in the perimeter of your object. That way all the knowledge needed to resolve a collision involving multiple adjacent edges lives in one place, and the physics engine can solve them simultaneously, rather than solving them one at a time and creating undesired behaviour at the seams between them. \$\endgroup\$
    – DMGregory
    Commented Sep 15, 2018 at 0:24
-1
\$\begingroup\$

for anyone still reading this adding a composite collider 2d to the tilemap and checking used by composite on the tilemap collider will fix this problem. :)

\$\endgroup\$
1
  • \$\begingroup\$ This is a good solution if the user is using the Tilemap component, but OP doesn't mention using this feature. \$\endgroup\$
    – DMGregory
    Commented Jul 12, 2020 at 11:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .