Advertisement
Guest User

Untitled

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