unity-game-enginegame-physics

How to fix snagging issue in Unity?


In Unity 2D, a sliding GameObject (my player in my platform game) will sometimes get stuck on the edge between two BoxCollider2D next to each other. Within a tilemap, this problem is easily solved by simply adding a CompositeCollider2D to the tilemap. However, in my game there are other objects that can't be grouped together in a tilemap, e.g. moving platforms or some kinds of ground tiles with special properties. Therefore the issue persists. Things I have tried:

  1. Changing the player's collider shape to a circle. This messes up certain aspects of the physics in my game where I expect a box and also instead of getting stuck it jumps slightly when sliding on those edges.
  2. Changing the collider to a square with the corners cut off (and various other shapes).
  3. Unsuccessfully attempting to write a script that detects sudden changes in velocity, verifies the cause, and moves the player along
  4. Messing with the physics settings. Setting the Baumgarte Time Of Impact Scale to 1.1 (under Physics 2D in Project Settings) appears to decrease the likelihood of the player getting stuck, but it causes other issues. Other settings do not change anything significantly.

Solution

  • I have finally found a solution

    Just add a CompositeCollider2D to each independent collider, even if it defeats the whole point of a CompositeCollider, i.e. the CompositeCollider is used for only one collider.