Using a Tilemap Collider 2D, and my rigidbodies keep getting stuck inbetween tiles. Is manually placing Edge Collider 2Ds my only solution?

Hi there. I’m working on learning some of Unity’s newish 2D features, and I’m looking at tilemaps and tilesets. Right now, I’m trying to decide between using a Tilemap Collider 2D or a series of 2D Edge Colliders for managing solid objects in a level. For reference, here’s what the colliders look like:


Tilemap Collider 2D (Many automatically placed squares and triangles): Tilemap Collider 2D

Edge Collider 2D (2 manually placed edge colliders): Edge Collider 2D


The Tilemap Collider is great because it’s automatic, but I’m running into an issue where my player object, a 2D rigid body, is occasionally getting stuck in between the tiles as its moving. Looking online for solutions, people seem to be suggesting that this is just how this collider works, they suggest using edge colliders instead. Edge Colliders do in fact solve my issue, but now I’m faced with the arduous task of outlining each level, each iteration of a level, with hundreds of these silly lines. So my questions are:


  1. Is there a way to fix the Tilemap Collider so that it works properly, someway to keep player objects from tripping over tile boundaries and getting stuck on walls? Is there some sort of physics settings I can change in the project settings? Something on the attribute maybe?

  1. If this is how Tilemap Colliders just work, what is even the point of them? Is this a bug that is going to be fixed, or is it just ‘as is’?

  1. If edge colliders are my only option, how can I automate it to work on a tile map to make it a viable option? Is there some hidden feature to somehow convert a tilemap collider to a series of edge colliders? I can’t seem to find it if there is.

For extra info, here’s the code I’m currently running for my player object. It’s very basic at the moment:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Test2DPlayer : MonoBehaviour
{
    private Rigidbody2D rb;
    private Vector2 moveVelocity;

    public float moveSpeed;

    //All used to see if player is standing on solid ground
    public bool isGrounded = false;
    public Transform isGroundedChecker;
    public float checkGroundRadius;
    public LayerMask groundLayer;

    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }

    // Update is called once per frame
    void Update()
    {
        Vector2 moveInput = new Vector2(Input.GetAxisRaw("Horizontal"), 0);
        moveVelocity = moveInput.normalized * moveSpeed;
    }

    private void FixedUpdate()
    {
        //rb.MovePosition(rb.position + moveVelocity * Time.fixedDeltaTime);

        rb.velocity = rb.velocity + moveVelocity;
        CheckIfGrounded();
    }

    void CheckIfGrounded()
    {
        Collider2D collider = Physics2D.OverlapCircle(isGroundedChecker.position, checkGroundRadius, groundLayer);
        if (collider != null)
        {
            isGrounded = true;
        }
        else
        {
            isGrounded = false;
        }
    }
}

Thanks for your help! Let me know if you need more info!

Found a possible solution: unity - Player gets stuck on edges between TilemapCollider2D tiles - Game Development Stack Exchange

Essentially:

1) For the TilemapCollider2D check the box "Used by Composite".

2) Then add the Component CompositeCollider2D (Found under Physics2D). 

3) This will automatically add a Rigidbody2D to your object if it doesn't have one already.

4) Change the "Body Type" of the Rigidbody2D to Kinematic unless you want physical interaction with the tilemap.

5) Profit.