NavMesh navigation and avoidance

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By vonflyhighace2
:warning: Old Version Published before Godot 3 was released.

I want to use the navmesh system that Godot has. Seems to be very basic in usage so I was hoping someone could help me.

1). Is it possible to create a navmesh during runtime?
2). how would obstacle avoidance work if I don’t want my character walking into a brick wall trying to get to the other side.

:bust_in_silhouette: Reply From: ingo_nikot

1.) Yes like:

var nav_mesh = NavigationMesh.new()
nav_mesh.set_vertices(nav_vertices)
for polygone_indices in nav_polygones:
  nav_mesh.add_polygon(polygone_indices)

var nav_mesh_inst = NavigationMeshInstance.new()
nav_mesh_inst.set_navigation_mesh(nav_mesh)
nav_mesh_inst.set_enabled(true)
navigation_node.add_child(nav_mesh_inst)

polygone_indices is an integer list, it tells the NavigationMesh how to connect the nav_vertices to polygones.
nav_polygones is a list of these integer lists.

2.) dont add the brick wall in the navmesh. If you have a maze, only add the floor to the navmesh, thats it!

i hope this brief example helps. i used this method so my ships can sail around the ilands.

Does this mean if I have a giant rock my character will wall around the rock and not try to walk through it? I’m coming from unity where you specifically tell the navigation mesh what’s an obstacle/ static object and this creates a mesh that accounts for such things.

vonflyhighace2 | 2017-01-13 00:33

dont add the ground below the rock than yes, he would avoid the rock.
there is also an navmesh 3d example in the example apps. if your map is static navigation-wise you can do it like they did.

my example is for a dynamicly created map which then stays static.

ingo_nikot | 2017-01-13 16:42

How would I get the nav_vertices. would I use get_vertecies on a mesh resource node that I want to create the navMesh on? also not sure what you mean about the nav_polygones. I know that get_vertecies returns a vector3 array of verticies, is that what nav_polygones would be?

vonflyhighace2 | 2017-01-15 00:47

my nav_vertices and nav_polys are getting created on runtime while i procedurally create my worldmap. if you do someting like that, then you already should have them. you dont get them, you create them.

if your map is created in the editor you dont need to create the navmesh on runtime. see the godot example application for navmesh. you only need the code stuff if you have an random map like i do!

about nav_vetices and nav_polygones

well nav_vetices is an Vector3Array.

imagine a pathway out of polygones, nav_vetices contains the position of your points.
but nav_vetices has are only the points! they dont contain the information how to connect them. for example a quad:
v1 = Vector3(…)
v2 = Vector3(…)
v3 = Vector3(…)
v4 = Vector3(…)

now the quad could be build as a quad itself or 2 trinangles. with only v1-v4 godot cant know what you want!

in this example i choose 2 triangles, so i need and indice list to tell godot how v1-v4 are connected:
triangle1: 1,2,3
triangle2: 2,3,4

the index is the the same index as the order you add the vector3 to the Vector3Array. So 1=v1,2=v2…

nav_polygones in my example is the list of lists of indices like:
[[1,2,3],[2,3,4]]
and nav_vertices:
[v1,v2,v3,v4]

i hope my explaination is sufficent. and sorry for the poor english.

ingo_nikot | 2017-01-15 22:03