Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

NavMeshAgent, SetDestination each Update

Discussion in 'Navigation' started by Wattosan, Sep 29, 2016.

  1. Wattosan

    Wattosan

    Joined:
    Mar 22, 2013
    Posts:
    460
    Hey,

    I've been toying around with NavMeshAgent and it seems that in order for them to surely reach their destination, the most sure way is to SetDestination each update. I have a game where their new target can change any second.

    Should I use a coroutine for setting the destination every second or two? Is it very very bad to call SetDestination each Update?
    How have you solved your issue with AI not reaching its destination before it stops?

    Thanks!
     
  2. Whiteleaf

    Whiteleaf

    Joined:
    Jul 1, 2014
    Posts:
    728
    SetDestination takes in a Vector3, which most likely means it doesn't track the object you're trying to move to. When you set the destination in Start, it finds that position once and moves to there. Let's say you put the destination to Player.position, it would move to their position; but if you move it won't update to your position because you set it once in start. However, if you set it every frame it will constantly follow the players position.

    I'd say Update if you want super precise movement - and co routines for delayed but less intensive movement. A co routine that sets the destination every 0.1 or 0.2 seconds would probably be better than Update though since there's no need to set the destination x (framerate) times a second.
     
    alysonlupo, marcospgp and twda like this.