troycheek wrote:local i = #waypoint
local x,y,z = waypoint[1],waypoint[2],waypoint[3]
While the wiki speaks of levels of details and whatnot, the waypoint table appears to mostly be a progression from origin to destination. The last waypoint is the closest one to the destination. If there is a path, this waypoint will be very close to the destination. If not, then this waypoint will be far away from the destination, probably back at the edge of whatever terrain or water which the unit finds impassible.
return x,y,z
Why return the coordinates of the last waypoint instead of a simple true/false? To make a true/false decision, you have to specify how close is close enough. The path does not always end exactly at the destination. If you want a unit to go to or through a particular position, you may want to get it very close. On the other hand, if you're trying to attack an enemy unit or build a structure at a particular position, it may be sufficient to know that you could get within a certain range.
Incorrect if the target can't be reached it returns nil. As the wiki says the resolutions of the waypoints decreases (there are 3 different levels of resolutions), so the final waypoint has a very low resolution and so it can somewhat off the desired spot. By using path:Next() the path gets updated and so the resolution will increase the more you come up to final pos.
Use the `radius` argument if you want to use different margins.
PS: Cause of the low resolution it can happen that it seems first that a spot is reachable, but the more you come up to it the resolution increases and so it can happen that the spots isn't reachable anymore. But that has nothing to do with the distance of the first assumption from the wanted target spot.