Setting node height of GridGraph at runtime

Hi there,

I have a grid graph that scans my (procedurally generated) world at runtime - its a pretty typical looking perlin noise map. What I’m trying to do is effectively ‘plateau’ the grid graph’s nodes above a certain height. This seemed simple enough - after scanning the world, I then iterate through my world and for each block that is higher than the threshold, I set node.position.y to a max y value as can be seen here:

foreach (Block block in blockGrid) {
                if (block == null) continue;
                GridNodeBase node = worldGraph.GetNode(block.worldX, block.worldZ);

                if (block.y > baseHeight + rampThreshold) {

                    node.position.y = Mathf.RoundToInt((baseHeight + rampThreshold) * scale);
                    worldGraph.CalculateConnectionsForCellAndNeighbours(node.XCoordinateInGrid, node.ZCoordinateInGrid);
                }
                node.Penalty += (uint)block.y * 1000;
}

However, no matter what I set the y value to, the graph always shows these plateaued areas with a y position of zero. If I log the y values though, they show up with the correct numbers. Here’s a screenshot of what I mean:

Here’s the side view perspective - basically instead of being at y=0, those areas should be a step above the others.

Imgur

And here’s what it looks like if I don’t try to set the heights:

Imgur

Is this purely an issue with the visual representation of the graph not being updated correctly? Or is it actually not updating the y values? Basically I just need to be able to make sure that connections work between the plateaued areas and the blocks around them (which as you can see in the first image currently isn’t working).

For some background - this grid is used for generating roads between points in the world. I want the roads to try and stick to the lower levels of the map as much as possible (hence the penalty assignment in the code above) but once they reach a certain level instead of generating roads I will generate tunnels through the mountains, which is why all the levels above a certain height don’t matter anymore, as they will simply be tunnels going through rather than over. The reason I scan the graph in the first place is because it correctly accounts for ramps between levels vs. impassable cliff faces through the MaxClimb property (you can see in the last image how some areas of different heights connect, and some don’t - where they connect is where ramps are).

Any help would be greatly appreciated!

Thanks,

-Chris

Note that node positions are stored in integer coordinates (Int3) not Vector3. The integer coordinates are in millimeter units.

You can convert between a Vector3 and an Int3 using:

node.position = (Int3)myVector3;