Multiple Waypoints ? (17093)

How can i change this script to be multiple waypoints instead of just two??

var targetA : GameObject;
var targetB : GameObject;
var speed : float = 0.1;

function FixedUpdate () {

    var weight = Mathf.Cos(Time.time * speed * 2 * Mathf.PI) * 0.5 + 0.5;
    transform.position = targetA.transform.position * weight
+ targetB.transform.position * (1-weight);

}

Also posted to the forums here: http://forum.unity3d.com/threads/82445-Multiple-Waypoints

1 Answer

1

First off, I'd use an array

var targets : GameObject[];

Second, I'd use Lerp to compute the weights. If you need non-linear, theres some script in the script wiki that does things like this, I think it's a Math replacement script. I recall modifying it to do almost the same thing you have here, don't know where I put that code though.