I want to make a Nav Mesh Agent follow a road and I’m struggling a bit with this (I’d like to do this on a terrain). Is there a tutorial or something I can study to help me accomplish this? Perhaps some example code I can look at? Or, alternately, is there something in the Unity Store that I can purchase that might help with this (that’s not too expensive, I’m poor).
If your roads are separate meshes from the rest of your environment, you could set the area cost of your roads lower than the cost of your environment. More info on Area Costs here.
I’m trying to sort through this. When I’m looking on the Navigation window, a “mesh” is actually the “Area” (where "Built-in 0 = Walkable) and so forth…is this correct? And I’m trying to test this. I don’t need any of the built in types at all … I merely need Grass and Road. I set Road to 1 and Grass to 10 (I’m just trying to get Nav Agent to follow road right now).
Okay, to get the “mesh” if I understand this so far, I think I should use two of the standard assets so I’m using two surface textures, “SandAlbedo” for the road and “GrassHillAlbedo” for the non-road.
But now, I’m not sure how to “bake” all this so that the different meshes will have different movement values? Could someone help me here?
It seems however I bake it, it will bake the entire terrain and make the entire terrain either grass or road. I can’t get the bake of the terrain to distinguish between grass and road so that they are separate costs for movement.
I’m currently using Unity version 2019.1 if that makes any difference.
To simplify my current objective, I’m trying to use the paint/brush feature on the terrain to paint a new texture on the terrain and then change the movement cost of that specific texture. Can this be done?
Ah, terrains are annoying with NavMesh Costs yes, since they are indeed calculated per mesh/object. The quickest way of getting this to work would be to build your road using scaled blocks for now.
Another option would be to use Unity’s NavMeshComponents (download here), and use the NavmeshModifierVolumes.
As for the builtin layers, the naming isn’t too important. All that matters is the numerical values. Your roads could just be Walkable whereas your grass can be any layer with a higher cost than that.
This way your agents will avoid the grass unless they absolutely can’t reach their goal using only the roads.