Forum rules - please read before posting.

Nav mesh and holes for randomly generated maps?

Can a nav mesh and holes be created with random shapes at run-time?

Comments

  • Obviously this would require coding to do.

    I'm guessing it's something like this thread (add vertices to a polygon collider):
    https://answers.unity.com/questions/624508/how-to-edit-a-polygoncollider2d-vertices-in-code.html

    I've never played with it, which is why I ask.
  • Welcome to the community, @frankbraker.

    Though you didn't specify, I'm guessing from your link that you're referring to 2D NavMeshes?

    2D NavMeshes rely on PolygonCollider2D components, so their shapes can be edited at runtime via script, as you've seen.  It wouldn't be trivial, and certainly something that would be specific to your own project given that the map generation would also be so.

    Another thread related to this subject can be found here:
  • edited October 2018
    Thanks I just now saw the reply and the link!  Yes it's for a 2D NavMesh.

    Okay and how to make holes: https://youtu.be/z1r7VjgufJ8
  • edited October 2018
    Manipulating Unity's own components is outside the scope of this forum, but you can rely on AC's internal hole-generation system once you have the hole shapes to incorporate them into the NavMesh.

    AC incorporates holes via separate PolygonCollider2D components that are referenced in the NavMesh Inspector - see the Manual's "Polygon Collider pathfinding".  Such components can also be added as holes to the NavMesh through script:

    NavigationMesh defaultNavMesh = AC.KickStarter.sceneSettings.navMesh;
    defaultNavMesh.AddHole (myHole);

    Where "myHole" is a PolygonCollider2D variable.  This'll add a hole with that component's shape to the default NavMesh (a NavigationMesh), so if you assign your generated NavMesh into the scene's default you can then amend its holes.
  • I appreciate your timely reply.  I will try this soon - fingers crossed.  Thank you!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.