duck

duck

Jun 28th, 2010
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private var beingDragged : Draggable;
  2. var speed : float = 0.5;
  3. private var trail : Array;
  4.  
  5. ////create path with linrenderer
  6. var lineWidth = 0.02;
  7. var lineMaterial : Material;
  8. private var line : LineRenderer;
  9.  
  10. function Start()
  11. {
  12.    lineObject = new GameObject("Line");
  13.    line = lineObject.AddComponent(LineRenderer);
  14.    line.SetWidth(lineWidth,lineWidth);
  15.    line.material = lineMaterial;
  16.    line.SetVertexCount(0);
  17.    trail = new Array();
  18. }
  19.  
  20.  
  21. function Move(newPoints : Array) {
  22.  
  23.     trail = trail.Concat(newPoints);
  24.  
  25.     // this loop steps through each point remaining in the array
  26.     while (trail.Length > 1)
  27.     {
  28.         thisPoint = trail[0];
  29.         nextPoint = trail[1];
  30.         dist = (thisPoint-nextPoint).magnitude;
  31.         lerpDist = 0.0;
  32.        
  33.         // this loop smoothly moves the object from the current point to the next
  34.         while (lerpDist < dist) {
  35.             i = lerpDist / dist;
  36.             transform.position = Vector3.Lerp(thisPoint, nextPoint, i);
  37.             transform.LookAt(nextPoint);
  38.             yield;
  39.             lerpDist += Time.deltaTime * speed;
  40.         }
  41.        
  42.         trail.Shift();
  43.         UpdateLine();
  44.     }
  45. }
  46.  
  47.  
  48. function UpdateLine()
  49. {
  50.     ///update line vector count
  51.     line.SetVertexCount(activeTrail.length);
  52.     var i = 0;
  53.     for (var drawLine : Vector3 in activeTrail)
  54.     {
  55.         //Debug.Log(drawLine);
  56.         ///loop over the array and appply the line
  57.         line.SetPosition(i, drawLine);
  58.         i++;
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment