Patrol script won't work.

So I’m literally just trying to have a character patrol through several checkpoints over and over again, but whenever I run the script, the player is moving super fast. No matter what I make the speed, it still goes really fast, so I don’t know what’s wrong. I’ve only been using unity for a few weeks so the answer’s probably stupid and obvious, but still.

var theEnemy : Transform;
var checkpoints : Transform[];

var currentCheckpoint = 0;

var speed = 0.01;

var currentDistance = Vector3.Distance(checkpoints[currentCheckpoint].position, theEnemy.position);

function Update(){


if(currentCheckpoint < checkpoints.length){
theEnemy.position = Vector3.MoveTowards(checkpoints[currentCheckpoint].position, theEnemy.position, speed * Time.deltaTime);
if(currentDistance<1){
currentCheckpoint++;
}
}
else{
currentCheckpoint = 0;
}


}

Vector3.MoveTowards

static function MoveTowards(current: Vector3, target: Vector3, maxDistanceDelta: float): Vector3; Description Moves a point current in a straight line towards a target point.

Looks like your parameters here are in wrong order:

theEnemy.position = Vector3.MoveTowards(checkpoints[currentCheckpoint].position, theEnemy.position, speed * Time.deltaTime);

Supposed to be like:

theEnemy.position = Vector3.MoveTowards(theEnemy.position, checkpoints[currentCheckpoint].position, speed * Time.deltaTime);