2

I'm not 100% sure what factors are important when deciding whether to use Unity's NavMesh vs an advanced pathing algorithm such as HPA* or similar. When considering the mechanics below, what are the implications of using Unity's NavMesh vs rolling my own algorithms:

  • Grid based real-time building.
  • Large number of AI, friendly, hostile, neutral. Into the hundreds. Not all visible on screen at once but the playfield would be very large.
  • AI adheres to a hierarchy. Basically does things where AI entities issues commands, receive commands, and execute them in tandem with one-another. This could allow for advanced pathing to be done on a single unit that relays rough directions to others where they can commence lower-level pathing to save on performance.
  • World has a strong chance of being procedural. I wanted to go infinite proc-gen but I think that's out of scope. I don't intend on having the ground plane being very diverse in regards to actual height, just the objects placed on it.
  • Additions and removals within the environment will be dynamic at run-time by both the player and AI entities.

I've read some posts talking about how NavMesh can't handle runtime changes very well but have seen tutorials/store assets that are contrary to that. Maybe I could combine methods too? The pathing is going to be a heavy investment of time so any advice here would be greatly appreciated.

Justin Anthony
  • 416
  • 1
  • 3
  • 13
  • 1
    It's tough to edit this question to make it escape SO's nebulous opinion-based criteria, but more important is that you're clearly pre-optimizing. I know that's an annoying thing to hear but I only mention it because I've been caught in the exact same trap myself this past month. I spent weeks working on faster methods only to find that in my prototype, there were other optimizations within unity that were far simpler to use. Specifically "world has a strong chance of being procedural" indicates that there are much bigger questions to answer before pathfinding (continued...) – Salvatore Ambulando Aug 21 '20 at 15:12
  • 1
    You've mentioned several different methods you could use to optimize pathfinding, so you know somewhere in your heart that there isn't one easy answer to this. This is a relevant question and answer (flow fields) that can be a big part of your solution - https://gamedev.stackexchange.com/questions/387/how-does-flow-field-pathfinding-work however, I'd recommend putting together a full prototype before trying to solve this. It'll most likely take less time than figuring out how to implement flow fields, and will give you a much clearer idea of your requirements, which will help optimization – Salvatore Ambulando Aug 21 '20 at 15:15
  • 1
    @Appleguysnake Thank you for the perspective. You're right in that it's too early to make a clear determination here. I appreciate your honest feedback. – Justin Anthony Aug 27 '20 at 17:46

1 Answers1

2

There are lots of solutions. It's way too much for a single answer, but here's some keywords to look into:

  • Swarm pathfinding
  • Potential fields
  • Flocking algorithms
  • Boids
  • Collision avoidance

Which one you use depends on how many units will be pathing at a time, whether they're pathing to the same place or different places, and how you want them to behave if multiple are going to the same place (eg. should they intentionally avoid collisions with each other? Take alternate routes when one is gridlocked? Or all just stupidly cram into the same hallway?)

BlueRaja - Danny Pflughoeft
  • 84,206
  • 33
  • 197
  • 283
  • Do you have any experience with Unity's NavMesh? I know it handles swarms pretty well, but I can't speak to how well it would handle a world that changes at runtime. A few years ago this would be no question but lately it seems there are more features with NavMesh. But is it too opinionated? – Justin Anthony Aug 19 '20 at 17:17
  • @JustinAnthony: I don't, sorry – BlueRaja - Danny Pflughoeft Aug 19 '20 at 18:20