How do I edit the navigation mesh for AI pathfinding?

local modifier = Instance.new("PathfindingModifier")
modifier.ModifierId = "Road"
modifier.Parent = game.Workspace.Land.Road

It seems to be very hard to find much info about this topic. Its pretty new and can’t seem to change the modiferId. The modifierId stays at nothing even though I’ve set it to “Road” in the script.

What I want to see (seeing the PathfindingModifier):

What it looks like for me:

The navigation mesh behaves differently depending on how you call CreatePath(). You can’t modify the navigation mesh directly, but you can use PathfindingModifiers and CreatePath() parameters to make paths that avoid parts of the navmesh, or paths that ignore obstacles on the navmesh.

When you call CreatePath, you can pass in a “Costs” map that specifies a numerical cost for walking over each material. If the cost of Plastic is 1, and the cost of Pavement is 10, the pathfinder considers every step over Pavement to be 10 times farther than a step over Plastic. If you set the cost of a material to math.huge (effectively infinite), the pathfinder will never choose to a path over that material.

PathfindingModifiers are a way of creating custom materials for the purposes of pathfinding. Your “Costs” map can include the cost for any pathfinding modifier ids you use. That’s really useful, because you can put a pathfinding modifier with the id “road” on your roads. When you calculate paths for cars, you can make the costs of all materials except roads math.huge. When you calculate paths for pedestrians, you can make the costs for roads math.huge.

From your screenshot, it looks like you want to be able to find paths that keep characters off the road, but allows them to cross at crosswalks. One way to do this would be to model your roads and crosswalks as different parts. Roads would have a child PathfindingModifier with the id “road” and crosswalks have a child PathfindingModifier with the id “crosswalk”. When you calculate paths for pedestrians, set the cost of “crosswalk” to 1, and “road” to math.huge. When you calculate paths for cars, set the cost of “road” to 1 and “crosswalk” to 1 (so cars can drive over crosswalks).

Here’s another very cool thing about PathfindingModifiers that might be useful to you: You can add and remove pathfinding modifiers with scripts, and path calculations respect those changes. So, for example, you could only attach the “crosswalk” modifier to your crosswalks when it’s safe to cross the road.

Good luck!

1 Like

I’ve tried using PathfindingModifier. If you insert the PathfindingModifier into a part and try and change the ModifierId in properties, it wont change. As well as in insert object the PathfindingModifier itself is slightly greyed out. What does it mean when the object is greyed out? I tried changing the ModifierId with a script as you saw in my original post but it didn’t work either. Can you test and see if you can change the ModifierId in properties?


Oh so this is why I can’t use it. I didn’t activate roblox beta features for the pathfindingmodifier. Still unfortunate since even if I get it working like I want, it wont work in a real game since it beta. It even said this in the article I linked but I might of missed that part. Sorry for the trouble.