duck

duck

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