Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Vector3 GetFurthestLineOfSightPosition(IndexedList<Vector3> path, float maxDistance)
- {
- var safePath = new IndexedList<Vector3>(path);
- Vector3 startPosition = Core.Player.Position;
- Vector3 furthestLosPosition = startPosition;
- Vector3 closestUnreachablePosition = safePath.LastOrDefault();
- // Find closest valid path point;
- for (int i = safePath.Index; i < safePath.Capacity; i++)
- {
- var point = path[i];
- if (startPosition.Distance(point) > maxDistance || !CanRayCast(startPosition, point))
- {
- closestUnreachablePosition = point;
- break;
- }
- furthestLosPosition = point;
- }
- var distance = furthestLosPosition.Distance(closestUnreachablePosition);
- if (distance > maxDistance)
- return furthestLosPosition;
- const float testIncrements = 2f;
- var totalSegments = distance / testIncrements;
- // Find closest valid portion of path.
- for (int i = 0; i < totalSegments; i++)
- {
- var point = MathEx.CalculatePointFrom(closestUnreachablePosition, furthestLosPosition, i * testIncrements);
- if (startPosition.Distance(point) > maxDistance || !CanRayCast(startPosition, point))
- break;
- furthestLosPosition = point;
- }
- return furthestLosPosition;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement