duck

duck

Oct 6th, 2010
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1.         float currentLength = 0;
  2.         float midPointI = 0;
  3.         int segmentNum = 0;
  4.         for (segmentNum = 0; segmentNum < routeData.Count; ++segmentNum)
  5.         {
  6.             float previousLength = currentLength;
  7.             Vector3 pointA = routeData[segmentNum];
  8.             Vector3 pointB = routeData[segmentNum % routeData.Count];
  9.             Vector3 segmentDelta = pointB - pointA;
  10.             float addLength = segmentDelta.magnitude;
  11.             currentLength += addLength;
  12.  
  13.             if ((currentLength/routeLength) > i)
  14.             {
  15.                 // the i point lies between these two!
  16.                 startPoint = pointA;
  17.                 endPoint = pointB;
  18.                
  19.                 midPointI = (i - (previousLength / routeLength)) / (addLength / routeLength);
  20.                 break;
  21.             }
  22.         }
  23.  
  24.  
  25.         Vector3 routePointPosition = Vector3.Lerp(startPoint, endPoint, midPointI);
Advertisement
Add Comment
Please, Sign In to add comment