From 15e35f27d2ece4db235005bc76ccb8faf2aaa237 Mon Sep 17 00:00:00 2001 From: smix8 <52464204+smix8@users.noreply.github.com> Date: Thu, 1 Jun 2023 11:40:13 +0200 Subject: [PATCH] Update navigation examples that use NavigationMesh.create_from_mesh() Updates navigation examples that use NavigationMesh.create_from_mesh() --- .../navigation_using_navigationmeshes.rst | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/tutorials/navigation/navigation_using_navigationmeshes.rst b/tutorials/navigation/navigation_using_navigationmeshes.rst index 7b8626b5cc5..d5ce14994f9 100644 --- a/tutorials/navigation/navigation_using_navigationmeshes.rst +++ b/tutorials/navigation/navigation_using_navigationmeshes.rst @@ -208,16 +208,22 @@ The following script creates a new 3D navigation region and fills it with proced NavigationServer3D.region_set_map(new_3d_region_rid, default_3d_map_rid) var new_navigation_mesh: NavigationMesh = NavigationMesh.new() - var new_plane_mesh: PlaneMesh = PlaneMesh.new() - new_plane_mesh.size = Vector2(10.0, 10.0) - new_navigation_mesh.create_from_mesh(new_plane_mesh) - + # Add vertices for a triangle. + new_navigation_mesh.vertices = PackedVector3Array([ + Vector3(-1.0, 0.0, 1.0), + Vector3(1.0, 0.0, 1.0), + Vector3(1.0, 0.0, -1.0) + ]) + # Add indices for the polygon. + new_navigation_mesh.add_polygon( + PackedInt32Array([0, 1, 2]) + ) NavigationServer3D.region_set_navigation_mesh(new_3d_region_rid, new_navigation_mesh) Navmesh for 3D GridMaps ~~~~~~~~~~~~~~~~~~~~~~~ -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. +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. .. tabs:: .. code-tab:: gdscript GDScript @@ -227,12 +233,21 @@ The following script creates a new 3D navmesh from the mesh of a GridMap item, c # enable navigation mesh for grid items set_bake_navigation(true) - # get mesh from grid item, bake and set a new navigation mesh for the library + # get grid items, create and set a new navigation mesh for each item in the MeshLibrary var gridmap_item_list: PackedInt32Array = mesh_library.get_item_list() for item in gridmap_item_list: - var item_mesh: Mesh = mesh_library.get_item_mesh(item) var new_item_navigation_mesh: NavigationMesh = NavigationMesh.new() - new_item_navigation_mesh.create_from_mesh(item_mesh) + # Add vertices and polygons that describe the traversable ground surface. + # E.g. for a convex polygon that resembles a flat square. + new_item_navigation_mesh.vertices = PackedVector3Array([ + Vector3(-1.0, 0.0, 1.0), + Vector3(1.0, 0.0, 1.0), + Vector3(1.0, 0.0, -1.0), + Vector3(-1.0, 0.0, -1.0), + ]) + new_item_navigation_mesh.add_polygon( + PackedInt32Array([0, 1, 2, 3]) + ) mesh_library.set_item_navigation_mesh(item, new_item_navigation_mesh) mesh_library.set_item_navigation_mesh_transform(item, Transform3D())