I could only add _start _end and _plain as parameters to CWaypointList:findPulledBeforeWaypoint() but before I do that somebody should take look at this:
getNearestSegmentPoint3D:
Code: Select all
-- Returns the point that is nearest to (X,Z,Y) between segment (A,B,C) and (D,E,F)
function getNearestSegmentPoint3D(x, z, y, a, b, c, d ,e ,f)
--y,c,f falling out
if( not y or not c or not f)then
return getNearestSegmentPoint(x ,z ,a ,b ,d ,e)
end
if a == d and b == e and c == f then
return CWaypoint(a, b, c)
end
local dx1 = x - a;
local dz1 = z - b;
local dy1 = y - c;
local dx2 = d - a;
local dz2 = e - b;
local dy2 = f - c;
local dot = dx1 * dx2 + dz1 * dz2 + dy1 * dy2;
local len_sq = dx2 * dx2 + dz2 * dz2 + dy2 * dy2;
local param = dot / len_sq;
local nx, nz , ny;
if( param < 0 ) then
nx = a;
nz = b;
ny = c;
elseif( param > 1 ) then
nx = d;
nz = e;
ny = f;
else
nx = a + param * dx2;
nz = b + param * dz2;
ny = c + param * dy2;
end
return CWaypoint(nx, nz ,ny);
end
Code: Select all
local segpoint = getNearestSegmentPoint3D(player.X, player.Z, player.Y, towp.X, towp.Z, towp.Y, fromwp.X, fromwp.Z, fromwp.Y)