I'm writing code for client-side pathfinding, the player can setup more than one destinationspoint and then queue to do the pathfinding in segments finally get a concatenated path.(actually it's for the long distance pathfinding, you can setup some halfway points and the final dest, to travel the further position)
Here's the pathsmoothing code so far and it's in lua:
local c = path.nextWork
while c + 1 < table.getn(path.finishedPath) do
-- Points to test
local p0 = coordToPoint(path.startPos, path.finishedPath[c-1])
local p1 = coordToPoint(path.startPos, path.finishedPath[c+1])
-- Has LOS
if TheWorld.Pathfinder:IsClear (
p0.x, p0.y, p0.z,
p1.x, p1.y, p1.z,
path.pathcaps
)
then
table.remove(path.finishedPath, c)
-- No LOS
else
c = c + 1
end
And the problem is that i found if i do path smooth for the concatenated path, (especially when some detours in the path),the result still exists some unnecessary point, the path smoothing code doesn't work well as expected.
For example, if i set two destinationsa segment assisted point C like this and get a path that walk around a square obstacle, the expected smoothing result should be A-->E, but the code actual not remove the B and D. Note C point was marked by player and not required to be exactly on the final path.What i want is the code that make the jointed path without any redundant steps


Here's the similar situations in game(DontStarveTogether):

