I’m using Unity in its 2D setup. When I use my code, I have my gameobject move, but it is translating to the last node before reaching the first node. is there a way to call the previous waypoint?
`using UnityEngine;
using System.Collections;
using Pathfinding;
public class AIpathmatt : MonoBehaviour {
public Transform target;
Seeker seeker;
Path path;
int currentWaypoint;
public float speed;
CharacterController characterController;
// Use this for initialization
void Start () {
seeker = GetComponent<Seeker> ();
seeker.StartPath (transform.position, target.position, OnPathComplete );
characterController = GetComponent<CharacterController> ();
}
public void OnPathComplete ( Path p) {
if (!p.error) {
path = p;
currentWaypoint = 0;
}
else {
Debug.Log (p.error);
}
}
void Update(){
if (path == null) {
return;
}
if (currentWaypoint >= path.vectorPath.Count) {
return;
}
Vector2 direction = (path.vectorPath [currentWaypoint] - transform.position).normalizedspeedTime.deltaTime;
transform.Translate (direction);
if (Vector2.Distance (transform.position, path.vectorPath[currentWaypoint])< 2){
currentWaypoint++;
}
}
}
`