![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Reisflocke |
Hello there!
I’m currently trying to implement path finding for my AI in my 3D Topw Down Game.
I created a custom level editor and now I wanne auto generate a working NavigationMesh.
My currnet approach (this code runs in the Editor via tool Script):
#SETUP (done in other parts of the script)
var floor_positions = [Vector2(1,3), Vector2(0, 4)] # and so on ...
var nav_mesh: ArrayMesh = load("something/something/nav_mesh.obj")
func create_node(node_new: Node, parent: Node=self) -> Node:
parent.add_child(node_new)
node_new.set_owner(get_tree().edited_scene_root)
return node_new
#**GENERATION (the nav mesh generation part)**
#generate nav mesh
var st := SurfaceTool.new()
for p in floor_positions:
var mesh_transform: Transform = Transform(Basis(), Vector3(p.x, 0.0, p.y))
st.append_from(nav_mesh, 0, mesh_transform)
var navigation: Navigation = create_node(Navigation.new())
navigation.hide()
var navigation_mesh_inst: NavigationMeshInstance = create_node(NavigationMeshInstance.new(), navigation)
navigation_mesh_inst.navmesh = NavigationMesh.new()
navigation_mesh_inst.navmesh.create_from_mesh(st.commit())
This code DOES generate a NavigationMesh, but once I try to test it with:
get_simple_path()
it returns:
What is the reason for this?
PS: if you need any more details on this complex question I’m happy to provide them