Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Suggestion on NavMesh 2D generation at runtime with infinite procedural generation.

Discussion in 'Navigation' started by msurz89, Apr 21, 2022.

  1. msurz89

    msurz89

    Joined:
    Apr 13, 2021
    Posts:
    8
    Hello!

    Let me start off by saying I began my jounrey of programming within the last year and Unity about the same time. I have come a long way since then, but I still come across walls that I cant seem to get across, this is one of them.

    I'm making a 2D game where one of the modes is to dungeon crawl, infinitely, with parts of the level being chosen from prefabs (mostly just premade chunks of a level that get stitched together when generating) on a list randomly when the player reaches a certain distance from the end of the last instantiated prefab. I got this part down, I can create prefab, after prefab, after prefab and everything works nicely! But, I'm having trouble adding a NavMesh to these newly instantiated prefab chunks so that my player stays within bounds. I am using the NavMesh components git to make NavMesh2D possible.

    I have tried:
    • making the prefab itself with a predefined baked NavMesh, but the player can only go as far as the first chunk, and stops, because he reached the end of the current NavMesh, even though the next NavMesh is overlapping/right next to, 1 unit away (all variations tried).
    • Bridging these NavMesh with links and off mesh links, doesn't work.
    • Dynamically creating a NavMesh at runtime around the player as he progresses, doesn't work.
    I am honestly stuck at this point and don't know what to try. I am open to suggestions on how to proceed at this point and welcome all input. If you need any info just ask! Or code, just ask! I'm not sure what to attach, so just ask away!
    Also, if there are other pathfinding options I am open minded about them as well. Hope to hear from anyone soon! Thanks!
     
  2. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    300
  3. msurz89

    msurz89

    Joined:
    Apr 13, 2021
    Posts:
    8
    DwinTeimlon likes this.
  4. msurz89

    msurz89

    Joined:
    Apr 13, 2021
    Posts:
    8
    Now that I have this working, a new problem arose. I guess this is the way of coding!

    Infinite procedural generation works with navmesh, but now my "Monster Spawner" (A game object with a script and collider trigger that instantiates enemies when the player enters its trigger) spawns all enemies outside of the navmesh, which looks to be like at coords (0,0). Any idea what might be causing this?
     
  5. msurz89

    msurz89

    Joined:
    Apr 13, 2021
    Posts:
    8
    Never mind figured it out! I had to use .Warp to properly place the agents when instantiating!
     
    DwinTeimlon likes this.