Advertisement
Guest User

Untitled

a guest
Nov 5th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 1.96 KB | None | 0 0
  1. diff --git a/Assets/AstarPathfindingProject/Modifiers/RaycastModifier.cs b/Assets/AstarPathfindingProject/Modifiers/RaycastModifier.cs
  2. index 7e0c5157..c1b68b0b 100644
  3. --- a/Assets/AstarPathfindingProject/Modifiers/RaycastModifier.cs
  4. +++ b/Assets/AstarPathfindingProject/Modifiers/RaycastModifier.cs
  5. @@ -142,6 +142,16 @@ namespace Pathfinding {
  6.             bool canBeOriginalNodes = points.Count == p.path.Count;
  7.             int startIndex = 0;
  8.  
  9. +           int[] nodeGroup = ArrayPool<int>.Claim(points.Count);
  10. +           nodeGroup[0] = 0;
  11. +           for (int i = 1; i < points.Count; i++) {
  12. +               if (Mathf.Abs(points[i].y - points[i-1].y) < 0.01f) {
  13. +                   nodeGroup[i] = nodeGroup[i-1];
  14. +               } else {
  15. +                   nodeGroup[i] = nodeGroup[i-1]+1;
  16. +               }
  17. +           }
  18. +
  19.             while (startIndex < points.Count) {
  20.                 Vector3 start = points[startIndex];
  21.                 var startNode = canBeOriginalNodes && points[startIndex] == (Vector3)p.path[startIndex].position ? p.path[startIndex] : null;
  22. @@ -157,7 +167,7 @@ namespace Pathfinding {
  23.                     }
  24.                     Vector3 end = points[endIndex];
  25.                     var endNode = canBeOriginalNodes && end == (Vector3)p.path[endIndex].position ? p.path[endIndex] : null;
  26. -                   if (!ValidateLine(startNode, endNode, start, end)) break;
  27. +                   if (!ValidateLine(startNode, endNode, start, end) && nodeGroup[endIndex] == nodeGroup[startIndex]) break;
  28.                     mn = mx;
  29.                     mx *= 2;
  30.                 }
  31. @@ -168,7 +178,7 @@ namespace Pathfinding {
  32.                     Vector3 end = points[endIndex];
  33.                     var endNode = canBeOriginalNodes && end == (Vector3)p.path[endIndex].position ? p.path[endIndex] : null;
  34.  
  35. -                   if (ValidateLine(startNode, endNode, start, end)) {
  36. +                   if (ValidateLine(startNode, endNode, start, end) && nodeGroup[endIndex] == nodeGroup[startIndex]) {
  37.                         mn = mid;
  38.                     } else {
  39.                         mx = mid;
  40. @@ -177,6 +187,7 @@ namespace Pathfinding {
  41.                 startIndex += mn;
  42.             }
  43.  
  44. +           ArrayPool<int>.Release(ref nodeGroup);
  45.             Memory.Swap(ref buffer, ref points);
  46.             buffer.ClearFast();
  47.             return points;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement