Prioritize path based on terrain splatmap textures

  • A* version: 5.3.4
  • Unity version: 2022.3.60f1

Players can paint roads on the terrain, which just paints one of the various textures to the splat map at runtime.

Is there any documentation on how to have AI strongly prefer walking along certain terrain textures?

Optionally I may generate a spline along the road which runs along the texture. Would following a spline be a more helpful way to have AI choose their paths?

In either case it needs to be based on priority, not locking to a path so they can still choose the “mostly” shortest route, but prefer to walk on roads because they will move faster etc.

No mesh involved, all unity terrain with standard terrain layers/textures.

The only posts I see related to this are 7+ years old.

Would you be able to sample the splatmap along the changed area/road texture to change tags/penalties?

I can sample either where the splat changes or along a spline etc.

Is changing tags the way to go? How does that work on very large tiles? Say you have a large open field with very large tiles. Then I draw a road via terrain textures. Nothing about that changes the navmesh tiles, how would tagging be accurate to a narrow road across a large open flat field?

As an example, the way it works for the RecastTerrain example is it won’t generate navmesh where there are trees, which is everywhere except the road so you get accurate navmesh only on the road:

In my case I currently don’t have any mesh or colliders to distinguish between things, but I do know where the terrain textures are different.

I’m thinking I may have to generate a mesh or something in the background that the player can’t see or interact with, just to have something for the raycast graph to work with. Is that the way to go?

Ahhh I see you’re on a recast graph, sorry about that-- so I’m playing around with it now just to double check my logic and here’s my line of thinking:

  • Use NavmeshCut to add more geometry where the sampled textures are “road”. For this you may need to look into mesh generation if you’re comfortable with that to define the shape of what geometry to make into a road section. You’ll want to set the NavmeshCut to isDual component to simply create new geometry
  • On top of that, use a GraphUpdateScene to set the new areas to a tag with the correct penalty delta. You can either use the existing mesh or just a list of points to define the area.

…The alternative would be to simply use a Grid Graph though- much simpler since you can just update the nodes and set their delta without the fussy mesh generation stuff. I think that’s more down to your individual project. From your screenshots, I do think a Grid Graph would work pretty well since it’s not super huge.

That’s not my map, just an example showing how that scene has a graph only on the road, but only because of the terrain trees.

My maps are 4 sq km or more, recast is the only option.

I didn’t even notice that was one of the examples- Never had a reason to open the terrain example :upside_down_face:

You may also want to look into the ProceduralGraphMover, depending on your gameplay.

Procedural does not fit my gameplay. I’m only asking about if astar has any built-in support to set priority for pathing based on terrain textures, or following a spline, on a recast graph. Sounds like that is a no.

Textures, no.
I always always double check my answers before I send them, and I was wrong!! Using TextureData is actually a thing! News to me :slight_smile:

Following a spline, you may want to check out Point Graphs… but that’s not a Recast Graph, so “no” for this.

TextureData says "Used for using a texture as a source for a grid graph. "

So that’s no for both then.