How to do 3D pathfinding in Godot??

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By God Of Theory

I already created a scene with a camera,a player(physics body with mesh instance as child) and some other object(physics body with mesh instance as child)…
Now,how do I create pathfinding for the player,so that it goes where the user clicks?
I know navigation node and navigation mesh instance node need to be used,but I have no idea about anything else…

I’ve tried creating a navigation node…
Then in the script attached to the navigation node, I created some navigation mesh using the mesh of the mesh instance that is already in my scene and add it into navigation using navmesh_add()
After that,I loop through the result of the get_simple_path() to draw the path using sphere,but the path is going through solid object,going into the ground,sometimes it would also return an empty array(no path)…

This could be of interest for you:

Tom Albrecht | 2020-03-20 18:20

I downloaded it,but I still don’t understand…
I was hoping there’s an online tutorial that have detailed explanation of how everything works and how it is implemented for games generated using procedural generation…

God Of Theory | 2020-03-21 00:22

Actually what is navmesh for??
Is it for setting the area where the player can move or is it to set the area where the player can’t move??

God Of Theory | 2020-03-21 01:10

NavigationMeshInstance creates/‘bakes’ a walkable mesh. This mesh is created for the MeshInstance’s that are children of the NavigationMeshInstance node. This NavigationMeshInstance node uses NavigationMesh data to bake to (the names are confusing but it’s basically settings in the inspector). After this select the NavigationMeshInstance node and click bake at the top of the scene view.

Magso | 2020-03-21 10:35

Ok,thanks…I’ll try that…
But I heard we can’t bake navmesh in code…
So since I’m procedurally generating my world,how do I bake my navmesh?

God Of Theory | 2020-03-21 11:12

This might help you

Magso | 2020-03-21 14:17

I’ve tried that,see my main question for details…
And also they speak something about offset,what does it mean??

God Of Theory | 2020-03-21 16:05

I’m not too sure, there’s no description for create_from_mesh(Mesh mesh) but I would imagine it uses the mesh given rather than using the algorithm in the baking process so the offset would be for the NavigationMesh’s cell height.

Magso | 2020-03-21 16:58

Ok,I’ve just done some research on pathfinding in Godot and I found out that there’s a Astar class in Godot.
So since navigation is giving me problems,do u think Astar would be a good idea??

God Of Theory | 2020-03-22 02:19

A* is nice for tile-based navigation, but it won’t provide you with dynamic obstacle avoidance if you need it.

Calinou | 2020-03-24 09:09