Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var waypoint : Transform[];
- var speed : float = 20;
- private var currentWaypoint; Transform;
- var loop : boolean = true;
- function Update () {
- if(currentWaypoint < waypoint.length){
- var target : Vector3 = waypoint[currentWaypoint].position;
- var moveDirection : Vector3 = target - transform.position;
- var velocity = rigidbody.velocity;
- if(moveDirection.magnitude < 1){
- currentWaypoint++;
- }
- else{
- velocity = moveDirection.normalized * speed;
- }
- }
- else{
- if(loop)
- currentWaypoint=0;
- }
- else{
- velocity = Vector3.zero;
- }
- }
- rigidbody.velocity = velocity;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement