[SOLVED] NavMeshAgent Create Imperfect Paths? [SOLVED]

Hello, I just started messing around with NavMeshes, and I could not find any way to stop Agents from always finding the perfect, and fastest path to it’s ‘destination?’ Has anyone else had this problem? And has anyone found a method? Thanks :slight_smile:

Interesting question. Unity’s built-in NavMesh system, in common with most path-planning algorithms, is designed to efficiently calculate the single least-cost path, according to some definition of “cost”. So, if you want different units to calculate different paths, you need to adjust their relative calculated cost of those paths.

Unfortunately, I don’t think it’s possible to add a random noise factor to path costs at runtime (which is what it sounds like you really want to do). However, one possibility is to ensure your NavMesh consists of lots of different layers (e.g. Road, Grass, Hill, Water etc. etc.) and then assign different per-layer costs for those layers for each agent. Thus, you will end up with units that have a preference to travelling across the “road” layer, some would prefer to go over “water” etc., and they should calculate different least-cost paths accordingly (note that your in-game terrain doesn’t actually have to be road/water/grass - it could all be the same surface, but with “invisible” costs to each unit just to artificially create variation).