Hi I am using an a A* Pathfinding solution to get a vector path and it works wonderful. however I am now having issues moving my objects character Controller along that path. I am using the below code. What Happens the objects moves along at its Speed towards the first VectorPoint in Vectorpath, then it slows Down to a CRAWL for a few seconds until it actually hits that exact vector point, then it moves normal to the next then crawls etc etc.
The result i want is the unit move at a standard speed throughout the whole path of Vectors then stops at the exact point of the last Vector.
It would be even nicer if somebody could help me figure out a way to get it to rotate at a “rotate speed” towards the next vector point before moving.
public void Update ()
{
if (path != null) { // if unit has a Path to follow move along the path
MoveAlongPath ();
}
}
public void MoveAlongPath ()
{
if (path != null && currentWaypoint >= path.vectorPath.Length) { // Reached the end of the move
moving = false;
performMove = false;
}
if (performMove == true && uAttributes.moveable == true && path != null) {
Vector3 dir = (path.vectorPath [currentWaypoint] - transform.position).normalized;
dir *= uAttributes.baseMovementSpeed * Time.deltaTime;
controller.SimpleMove (dir);
Vector3 my2dPosition = new Vector3 (transform.position.x, 0, transform.position.z);
if (Vector3.Distance (my2dPosition, path.vectorPath [currentWaypoint]) == 0) {
currentWaypoint++;
}
}
}