Contact Triggered Waypoint

Does anyone have an idea on how to make it so that once a trigger hits an object, the object is forced along a way-point that's ahead of it and forced to move along it until it reaches the end of the way-point?

You would just setup a waypoint script that is activated on collision like you describe.


var wayPoints : Vector3[] = new Array(); //points to move to
var moveToWayPoint : boolean = false; //whether to move to points
var startPosition : Vector3; //where we are moving from
var speed : float = 0.5; //how fast to move (1/speed seconds to move between points)
private var weight : float = 0; //how far we've moved from between points
private var wayPoint : int = 0; //the point we're moving to

Update() {
    if(moveToWayPoint && startPosition) { //moving
        weight += Time.deltaTime * speed; //update how far
        if(weight >= 1) { //move to the next point
            weight -= 1;
            startPosition = wayPoints[wayPoint];
        if(wayPoint < wayPoints.Length) { //not at the end, so move
            transform.position = Vector3.Lerp(startPosition, wayPoints[wayPoint], weight);
        else { //at the end, so reset
            weight = 0;
            wayPoint = 0;
            moveToWayPoint = false;


OnTriggerEnter(other : Collider) { //collided so make it move to waypoints
    var script : MoveScript = other.gameObject.GetComponent(MoveScript);
    script.StartPosition = other.transform.position;
    script.moveToWayPoint = true;

You could put your waypoints wherever you like or generate them somehow (finding one which is ahead of it? what defines being ahead?).

Because of the poor English, I'm not sure if you meant waypoint (singular) (it should read "...the object is forced along a path to a waypoint..." and "...until it reaches the waypoint?") or waypoints (plural) (it should read "...the object is forced along a path of waypoints..." and "...until it reaches the last waypoint?"), so I went with plural and if you only want one, you can simplify it from there.