Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. public Vector3 GetFurthestLineOfSightPosition(IndexedList<Vector3> path, float maxDistance)
  2. {
  3. var safePath = new IndexedList<Vector3>(path);
  4. Vector3 startPosition = Core.Player.Position;
  5. Vector3 furthestLosPosition = startPosition;
  6. Vector3 closestUnreachablePosition = safePath.LastOrDefault();
  7.  
  8. // Find closest valid path point;
  9. for (int i = safePath.Index; i < safePath.Capacity; i++)
  10. {
  11. var point = path[i];
  12. if (startPosition.Distance(point) > maxDistance || !CanRayCast(startPosition, point))
  13. {
  14. closestUnreachablePosition = point;
  15. break;
  16. }
  17. furthestLosPosition = point;
  18. }
  19.  
  20. var distance = furthestLosPosition.Distance(closestUnreachablePosition);
  21. if (distance > maxDistance)
  22. return furthestLosPosition;
  23.  
  24. const float testIncrements = 2f;
  25. var totalSegments = distance / testIncrements;
  26.  
  27. // Find closest valid portion of path.
  28. for (int i = 0; i < totalSegments; i++)
  29. {
  30. var point = MathEx.CalculatePointFrom(closestUnreachablePosition, furthestLosPosition, i * testIncrements);
  31. if (startPosition.Distance(point) > maxDistance || !CanRayCast(startPosition, point))
  32. break;
  33.  
  34. furthestLosPosition = point;
  35. }
  36. return furthestLosPosition;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement