Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var waypoint : Transform[];
  2. var speed : float = 20;
  3. private var currentWaypoint; Transform;
  4. var loop : boolean = true;
  5.  
  6. function Update () {
  7.     if(currentWaypoint < waypoint.length){
  8.         var target : Vector3 = waypoint[currentWaypoint].position;
  9.         var moveDirection : Vector3 = target - transform.position;
  10.  
  11.         var velocity = rigidbody.velocity;
  12.         if(moveDirection.magnitude < 1){
  13.             currentWaypoint++;
  14.         }
  15.         else{
  16.             velocity = moveDirection.normalized * speed;
  17.         }
  18.     }
  19.     else{
  20.         if(loop)
  21.             currentWaypoint=0;
  22.         }
  23.         else{
  24.         velocity = Vector3.zero;
  25.         }
  26.     }
  27.  
  28.     rigidbody.velocity = velocity;
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement