A* Pathfinding Project

Assigning Navmesh generated at runtime


#1

Bought the Pro Version, very cool stuff. Been digging through the forums and have a specific question though:
Like many others, I’m trying to get Pathfinding working with spherical or rather, just non-planar objects. I’ve downloaded the beta version from a while back where you Demo that specific idea and that works the way I’d like it to.

Heres the rub: I’d like to generate the mesh I’m using at runtime, allow the player to make all the tweaks they want in the editor, and when they are done, use their final mesh, (which wont change from this point forward), to create a navmesh on a mostly spherical object.

For a little background, what I’m basically starting with is a cube made up of 6 separate planar meshes each facing a different direction. I’m creating the vertices and subsequent triangles for the mesh using code. Then I set each vertex to be the same distance, (the radius of the planet) from it’s center. Then I use noise to deform it further. The basic set up is detailed below:

The plan is then to combine the 6 separate meshes into a single one, then use that mesh as the basis for the navmesh.
Problem is, I’ve tried for a while to figure out how to manually assign this mesh to the graph at runtime and I’ve dug through the long forum post I saw dedicated to this, (Navmesh on a spherical planet), but haven’t found an answer to what I’m looking for.

So TLDR, is what I’m trying to do possible out of box or with a few changes to the code? Any help would be greatly appreciated.


#2

UPDATE: Seemed to have managed to do this bit after a bit of tooling around but now I’m on to a bigger issue. I want to define the oceans as oceans and so would like to tag each node in the ocean as an ocean. In theory this seems simple to me: for each point on the mesh, find out whether it is in the ocean by figuring out if its distance from the center of the planet is less than or equal to 0, (because water level is always at 0), then change all nodes nearby to that point to have the ocean tag instead. Problem is, I can’t find a way to do this in the API, as everything I have tried doesn’t seem to alter any tags.
Do you have any idea how I could achieve this?


#3


This is my current plan of attack for setting nodes nearby to vertices to have a tag.


#4

Seems I keep asking questions and then digging deeper into the documentation and finding little bits that help me piece it together. I think I’ve figured out setting oceans (and mountains) as i described using the procedural mesh. Will come back if I have further questions. If someone else is struggling in this vein, please let me know and I’ll try to pass on what I learned. c:


#5

Nice that you figured some stuff out.
Some comments

The mesh can be set using

AstarPath.active.data.navmeshGraph.sourceMesh = someMesh;
AstarPath.active.Scan();

It might be easier to go through the nodes instead of doing a GetNearest call every time:

AstarPath.active.AddWorkItem(() => {
    AstarPath.active.data.navmeshGraph.GetNodes(node => {
        if (((Vector3)node.position - sphereCenter.position).magnitude < planetRadius) {
             node.Tag = 1;
        }
    });
});