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\$ – TomTsagk Sep 28 '18 at 11:58
  • \$\begingroup\$ @TomTsagk I could but that seems less elegant than forcing it to update the distance. \$\endgroup\$ – PStag Sep 28 '18 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\$ – TomTsagk Sep 28 '18 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.