# Graph erosion excluding dynamic obstacles

#1

Hi,

I’ve been experimenting with graph erosion on a layered grid graph and have found that the erosion also applies to dynamic obstacles. Is there anyway to disable this? Ideally when i initially bake the grid graph it has erosion but not with the obstacles.

Cheers

#2

Hi

How do you create your dynamic obstacles?

#3

Thanks for the quick response, I’m currenty using the dynamic grid obstacle component however I could probably manually update the graph as my game works entirely on a grid based system so i know all the exact coordinates and sizes for obstacles. The obstacles are static, but can be built and destroyed by the player so maybe doing it without the compoenent would be quicker? if so are there any guides for manually updating a layered grid graph?

#4

Hi

If you know the exact coordinates that you need to update then I’d recommend doing that.

#5

Cheers,

Seems relatively straight forward, but how do you distinguish between layers of a layered grid graph for example with a bridge how do you differentiate between the nodes on the bridge and the floor below?

#6

This depends on how your obstacle info is represented. Are your obstacles just objects in the world or do you have layer info for them as well?

One of the simplest methods if you have a bounding box is

``````Bounds bounds = ...;
var grid = AstarPath.active.data.gridGraph;
foreach (var node in grid.GetNodesInRegion(bounds)) {
node.Walkable = false;
}
});
``````

#7

That could work as all of the obstacles have colliders, my only concern is how fast is that get nodes in region function? all dynamic obstacles are fixed to a grid, i liked this example in the documentation

``````for (int z = 0; z < gg.depth; z++) {
for (int x = 0; x < gg.width; x++) {
var node = gg.GetNode(x, z);
// This example uses perlin noise to generate the map
node.Walkable = Mathf.PerlinNoise(x * 0.087f, z * 0.087f) > 0.4f;
}
}
``````

but obviously that is 2 dimensional and i dont know how to access the y dimension if there are different layers, is it a simple y coordinate that only has a size of 1 when there are no overlapping layers?

#8

The layered grid graph has an overload for GetNode that takes 3 parameters.