Waypoints- I want to add on to this script

How would I rewrite the following to add more waypoints?

Thanks,

Greg

The following script is attached to the moving object. (waypoint.js)

//waypoint.js
var start : Transform;
var end : Transform;
private var timer : float;
var travelTime: float;

function SetWaypointPath(s : Transform, e : Transform)
{
   if(s != start  e != end)
   {
      start = s;
      end = e;
      timer = 0.0;
   }
}

function Update()
{
   timer += Time.deltaTime;
   if(start != null  end != null)
   {
      var percentage : float = timer / travelTime;
      transform.position = Vector3.Lerp(start.position, end.position, percentage);   
   }
}

Here is the waypoint spot script (waypointTrigger.js)

//waypointTrigger.js
var waypoint1 : Transform;
var waypoint2 : Transform;
var way : waypoint;

function OnTriggerEnter (zone : Collider)
{
   if(zone.CompareTag("Roach"))
   {
      way.SetWaypointPath(waypoint1,waypoint2);
   }
}

Hi Greg,

There is a code snippet about waypoint on Unity wiki which is called “Seek Steer”. It’s in C# though. But the method is that you make a waypoint object you can duplicate in your 3D world and with a simple incrementation, you can have a huge number of points. Maybe it can provide you some help.

Can’t you do that in your .js script ?

EDIT: Here is the code.

http://www.unifycommunity.com/wiki/index.php?title=SeekSteer

Thanks for the link Darsh.
I tried the code, but need the waypoint array to constrain to one plain. I appreciate your help!

Thanks,

Greg

If you need to constrain the points to the XZ plane (for the ground, say) then it is easy to modify the code to do this. A nice way to go is to define a vector called xz:-

Vector3 xz = Vector3.right + Vector3.forward;

…and then use Vector3.Scale to multiply this vector by the waypoint position:-

Vector3 waypointXZ = waypoint.Scale(xz);

If the plane is not one of the axial planes, then it’s probably possible but might be more difficult.