k1 = #points;
--log("Move to");  	  

for k,v in pairs(points) do
	unit.AppendWaypoint(GetTerrainPoint(v));
end

function CheckPoint()
--log("CheckPoint "..k1);
	if CalcDistance(object.GetPosition(), points[k1]) < distance then
		if unload then
			unit.UnloadAll();
		end
		AIparts:RemovePeriodic("CheckPoint");
	end
end

AIparts:AddPeriodic("CheckPoint", check_timeout, CheckPoint);
