Question by
harveyrush · Apr 03, 2017 at 03:13 PM ·
2d gamepathfindingnavigationpathfollowing
2d NPC pathing
How can I get my 2D NPC to remember the path it has taken to chase the player and return following that path to it's original position when it stops chasing? I'm still new to unity and completely new to 2d so can't figure out a 2d navmesh alternative, I've written a small script but it seems to be completely useless and I think i'm at a dead end. any help would be so greatly appreciated.
IEnumerator pathWait()
{
Vector3 previouspos = transform.position;
yield return new WaitForSeconds(3f);
movepos++;
// Debug.Log(Vector3.Distance(transform.position, previouspos));
if (Vector3.Distance(transform.position, previouspos) >200)
{
Debug.Log("moved 5");
// returnPath.Add(transform.position);
returnPath[movepos] = this.transform.position;
Debug.Log(movepos);
}
}
Comment
Your answer
Follow this Question
Related Questions
2D platformer AI 0 Answers
make a self-driving car, combine Navimesh and waypoint? 1 Answer
Making the AI to reach the destination without a Navmesh? 0 Answers
Farthest Reachable Destination 0 Answers