- Home /
A* Procedural Terrain
I have tried to ask on the A* forum, but with no luck. So now I have decided to try here:
This script currently only moves the A* grid, but I would also like it to calculate the new nodes on the terrain, but can't figure out how to make it work. I have also tried to check the procedural example, but that was what I made the following code out of. I would also prefer not to rescan the whole terrain each time, because it takes something like 90ms
function UpdatePathFinding() {
var Center = Vector3(((CurrentTileX + 1) * terrainSize) - (terrainSize/2), 0, ((CurrentTileZ + 1) * terrainSize) - (terrainSize/2));
graph.center = Center;
graph.GenerateMatrix ();
var width = graph.width;
var depth = graph.depth;
var nodes : GridNode[] = graph.nodes;
for (var z = 0; z < depth; z++ ) {
for (var x = 0; x < width; x++ ) {
graph.UpdateNodePositionCollision(nodes[z*width + x], x, z, false);
graph.CalculateConnections (nodes, x, z, nodes[z*width+x]);
}
}
}
EDIT: How can I scan a specific grid graph or only scan a certain part of a graph.
Okay, got that working, but wouldn't I need to move the existing ones a tile back?
You could try to use GUOs (GraphUpdateObject); Basically a gameoject with the GUO script on it wherein you define the graph's area to be updated.
Answer by Jeff-Kesselman · Nov 23, 2014 at 01:37 AM
One would assume you would replace the 0 values in your loops with Xmin and Y min, and depth and width with the depth and width of the sub section you are scanning.
Having said that, this code wasn't written with that in mind so probably some re-writing will be in order.
No, we wont rewrite it for you.
Your answer
![](https://koobas.hobune.stream/wayback/20220613172204im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Procedural Object Avoidance 1 Answer
Rivers on procedurally terrain 0 Answers
Vector math problem 2 Answers
how do i procedurally generated perlin noise infinitely c# 0 Answers
A* endless loop 0 Answers