How to know the length of path when using navigation2D system

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

Just like the pic.
By using the navigation2D system, the enemy tracing after player follow the path indicated by arrow line. How can I know the length of dynamic path?

Thank you for reading, I am sincerely appreciate your assist!
Feel free to share your thoughts even you may not have a clear solution, I believe your thinking can definitely inspire us to get somewhere:)

:bust_in_silhouette: Reply From: Konishi

Hey! I am the same one who came up with this question. Now I found a solution. But pay attention, this solution not supported in future version Godot)

The code as follow will return a VectorArrayPool including every turning points on the way to target player

Now all we got to do is that sum up the distance from “enemy to turning point 1”, “turning point 1 to point2”… until “the last turning point to player”

Hope this solution can benefit everyone encounter the same problem like me:)

If you are using like Godot 4. Navigation2DServer.map_get_path()can be employed to replace the previous code sinceNavigation2D.get_simple_path since Navigation2D is no more supported:)