I want to implement 3D pathfinding for my NPCs to the project I am working on and I am curious about the different approaches one can take to achieve this.
I know there is the “Defold Detour” asset but I would like to learn about any alternatives one could use (or you are using)
But the best (and perhaps only) option for 3D space is a navmesh(Defold Detour), especially if you want to include different heights like platforms or ladders.
If the world is flat you can simply use ray casts for vision cone and direct the enemy to the player by preventing obstacles.
However, the choice of algorithm can vary depending on the project. In a flat environment, a straightforward A-star algorithm may suffice. For instance, I employed this approach: https://www.youtube.com/watch?v=Q9rUgZJ1HXQ&feature=youtu.e. The map was dynamically created at the beginning of the level, with multiple rays per cell perpendicular to the level. If these rays encountered a collider, the cell was designated as untraversable.
It should work for even non-flat terrains Thats how I am using it also. Raycast a grid of rays like rain falling down and continuously 16 raycasts per frame. Which probe the surface and create a heightmap. Then you can use it for A-star as a cost function. Only issue it can be expensive and obviously you need a lot of those rays to cover large map, and can easily miss small obstacles