Skip to content

Commit 407bc0b

Browse files
authored
Merge pull request godotengine#7453 from smix8/update_navmesh_create_from_mesh_4.x
2 parents 5798bf2 + 15e35f2 commit 407bc0b

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

tutorials/navigation/navigation_using_navigationmeshes.rst

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,22 @@ The following script creates a new 3D navigation region and fills it with proced
208208
NavigationServer3D.region_set_map(new_3d_region_rid, default_3d_map_rid)
209209

210210
var new_navigation_mesh: NavigationMesh = NavigationMesh.new()
211-
var new_plane_mesh: PlaneMesh = PlaneMesh.new()
212-
new_plane_mesh.size = Vector2(10.0, 10.0)
213-
new_navigation_mesh.create_from_mesh(new_plane_mesh)
214-
211+
# Add vertices for a triangle.
212+
new_navigation_mesh.vertices = PackedVector3Array([
213+
Vector3(-1.0, 0.0, 1.0),
214+
Vector3(1.0, 0.0, 1.0),
215+
Vector3(1.0, 0.0, -1.0)
216+
])
217+
# Add indices for the polygon.
218+
new_navigation_mesh.add_polygon(
219+
PackedInt32Array([0, 1, 2])
220+
)
215221
NavigationServer3D.region_set_navigation_mesh(new_3d_region_rid, new_navigation_mesh)
216222

217223
Navmesh for 3D GridMaps
218224
~~~~~~~~~~~~~~~~~~~~~~~
219225

220-
The following script creates a new 3D navmesh from the mesh of a GridMap item, clears the current grid cells and adds new procedual grid cells with the new navmesh.
226+
The following script creates a new 3D navigation mesh for each GridMap items, clears the current grid cells and adds new procedual grid cells with the new navigation mesh.
221227

222228
.. tabs::
223229
.. code-tab:: gdscript GDScript
@@ -227,12 +233,21 @@ The following script creates a new 3D navmesh from the mesh of a GridMap item, c
227233
# enable navigation mesh for grid items
228234
set_bake_navigation(true)
229235

230-
# get mesh from grid item, bake and set a new navigation mesh for the library
236+
# get grid items, create and set a new navigation mesh for each item in the MeshLibrary
231237
var gridmap_item_list: PackedInt32Array = mesh_library.get_item_list()
232238
for item in gridmap_item_list:
233-
var item_mesh: Mesh = mesh_library.get_item_mesh(item)
234239
var new_item_navigation_mesh: NavigationMesh = NavigationMesh.new()
235-
new_item_navigation_mesh.create_from_mesh(item_mesh)
240+
# Add vertices and polygons that describe the traversable ground surface.
241+
# E.g. for a convex polygon that resembles a flat square.
242+
new_item_navigation_mesh.vertices = PackedVector3Array([
243+
Vector3(-1.0, 0.0, 1.0),
244+
Vector3(1.0, 0.0, 1.0),
245+
Vector3(1.0, 0.0, -1.0),
246+
Vector3(-1.0, 0.0, -1.0),
247+
])
248+
new_item_navigation_mesh.add_polygon(
249+
PackedInt32Array([0, 1, 2, 3])
250+
)
236251
mesh_library.set_item_navigation_mesh(item, new_item_navigation_mesh)
237252
mesh_library.set_item_navigation_mesh_transform(item, Transform3D())
238253

0 commit comments

Comments
 (0)