# The distance along a path

Is there a way to compare the overall pathfinding distances between two different paths? For example, lets assume we are using Pathfinding Service, and have multiple Computed Paths. How would this then work? Would you have to manually calculate the distances between each Waypoint, and add them all up, or is there a shorter, much more efficient way to do it?

Couldnâ€™t you just check the Magnitudes of the Distance of the Paths & compare it to a range? (SumOfAllPathDistancesUsingMagnitude / TotalNumberOfPaths)

Not sure if this would be what you want

1 Like

Thatâ€™s what I meant by manually calculating all the distances. Iâ€™m asking whether there is a property or function built in to automatically do this.

I donâ€™t know of any built in function for this service that finds the best path. However, you can use a path finding algorithm to accomplish this.

A good pathfinding algorithm is Djikstraâ€™s algorithm. Here is a function that finds the shortest path using it:
https://developer.roblox.com/en-us/recipes/dijkstra-s-algorithm

I donâ€™t believe there is a built-in function for getting all of the distances, youâ€™d need to set up your own way of doing so using some math