Hello,
`import Pathfinding;
#pragma strict
var targetPosition : Transform;
private var seeker : Seeker;
private var controller : CharacterController;
private var path : Pathfinding.Path;
var speed : float = 100;
private var nextWaypointDistance : float = 3;
private var currentWaypoint : int = 0;
function Start ()
{
seeker = GetComponent(Seeker);
controller = GetComponent(CharacterController);
//seeker.StartPath (transform.position,targetPosition, OnPathComplete);
CalculatePath();
}
function OnPathComplete(p : Pathfinding.Path)
{
Debug.Log(“Got a path, but did it have an error?” + p.error);
if(!p.error)
{
path = p;
currentWaypoint = 0;
}
}
function Update()
{
if (path == null) {
//We have no path to move after yet
return;
}
if (currentWaypoint >= path.vectorPath.Length) {
Debug.Log ("End Of Path Reached");
return;
}
//Direction to the next waypoint
var dir : Vector3 = (path.vectorPath[currentWaypoint]-transform.position).normalized;
dir *= speed * Time.fixedDeltaTime;
controller.SimpleMove (dir);
//Check if we are close enough to the next waypoint
//If we are, proceed to follow the next waypoint
if (Vector3.Distance (transform.position,path.vectorPath[currentWaypoint]) < nextWaypointDistance)
{
currentWaypoint++;
return;
}
}
function CalculatePath()
{
while(true)
{
seeker.StartPath (transform.position,targetPosition.position, OnPathComplete);
yield WaitForSeconds(0.4);
}
}`
When the object is far away from its target (+ 5m) it moves smoothly. However, if it comes any closer, the movement gets slower and slower, and starts moving in jerky little jumps. Help?