I have an issue with the nav agent in my game. That I am using the remaining distance to determine the next state of the AI.

When the navagent is first given a destination it uses the previous distance until it is next updated.

So my plan is to find the memory of the remaining distance and alter it when I set the destination. Is that possible or is there a better way?

  • \$\begingroup\$ So the problem is that you do something like agent.destination = x; but the remaining distance updates only on the next frame? Would it be a problem if you waiting one frame? Instead of finding the memory of remaining distance (which is both impossible and a not very good idea) couldn't you just use another variable that has this "altered value" and use that until remaining distance updates? \$\endgroup\$ Sep 28, 2018 at 11:58
  • \$\begingroup\$ @TomTsagk I could but that seems less elegant than forcing it to update the distance. \$\endgroup\$
    – PStag
    Sep 28, 2018 at 15:47
  • \$\begingroup\$ When you say something like "find the memory of the remaining distance and alter it" this hints that you can calculate the remaining distance yourself, in which case, why do you want to wait for the variable to update? Unfortunately Unity is very generous in giving away frames when it comes with NavMesh and NavMeshAgent, so unless you write something manually, there's no other alternative. \$\endgroup\$ Sep 28, 2018 at 15:53


You must log in to answer this question.

Browse other questions tagged .