Search Unity

Made some components to bake 2D colliders into NavMeshSurfaces

Discussion in '2D' started by Sharlatan, Jan 13, 2019.

  1. Sharlatan

    Sharlatan

    Joined:
    Jul 23, 2013
    Posts:
    111
    Hey everybody!

    I'm not sure if this is the right sub forum for this kind of post. If not, please let me know what would be a more appropriate one.

    I've occasionally seen the question, how one can bake 2D colliders into NavMeshes. However, this isn't supported and I only found projects that remedy this situation for very specific kinds of situations (e.g. for rectangular tilemaps).

    This week, I had the need for such a thing myself. It didn't take too much time to come up with a solution that worked for my use case. Then, I was thinking to myself that it wouldn't take too much of an effort to make it a little more polished and multipurpose, which would hopefully make it useful to other people as well.
    In hindsight, I'm almost glad for my naivete. Making it more useful for general use took maybe 3 times as long as making it work for my case. If I knew beforehand how bad may estimation was, there's a good chance I'd have just stopped right there :D

    Anyway: I made some components that allow you to bake 2D colliders into a NavMesh:
    https://github.com/SharlatanY/NavMeshSurface2DBaker

    Here's an example of a hex tilemap (red tiles have a collider):



    Supported colliders:
    • BoxCollider2D
    • CircleCollider2D
    • PolygonCollider2D
    • CompositeCollider2D
    • TilemapCollider2D (For those to work, you have to make them part of a CompositeCollider2D, though!)

    Also, can a moderator tell me if I'm allowed to cross-post this to the navigation forum? The project's totally free, so, I'm obviously not trying to advertise/make money. I'd just like to reach people that could benefit from this.
     
    septia likes this.