Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

NavMeshAgent's velocity and desired velocity randomly dropping to 0.

Discussion in 'Scripting' started by invulse, Apr 13, 2012.

  1. invulse

    invulse

    Joined:
    Nov 29, 2010
    Posts:
    128
    In my game I have anywhere from 0-20 navmeshagents present at one time, but I am experience an issue randomly when new agents are added to the game at runtime. Sometimes it appears that when new agents are added, existing agents velocity and desired velocity will immediately go to 0 for a few frames, then slowly accelerate back to normal.

    Below is the debug output I am getting when this happens.

    AGENT: 2.6 VELOCITY: (1.6, -0.4, -2.1) DES VELOCITY: (1.6, 0.0, -2.1)
    AGENT: 2.6 VELOCITY: (1.6, -0.4, -2.1) DES VELOCITY: (1.6, 0.0, -2.1)
    AGENT: 2.6 VELOCITY: (1.6, -0.4, -2.1) DES VELOCITY: (1.6, 0.0, -2.1)
    AGENT: 2.6 VELOCITY: (1.6, -0.4, -2.1) DES VELOCITY: (1.6, 0.0, -2.1)
    AGENT: 2.6 VELOCITY: (1.6, -0.4, -2.1) DES VELOCITY: (1.6, 0.0, -2.1)
    AGENT: 2.6 VELOCITY: (0.0, 0.0, 0.0) DES VELOCITY: (0.0, 0.0, 0.0)
    AGENT: 2.6 VELOCITY: (0.0, 0.0, 0.0) DES VELOCITY: (0.0, 0.0, 0.0)
    AGENT: 2.6 VELOCITY: (0.0, 0.0, 0.0) DES VELOCITY: (0.0, 0.0, 0.0)
    AGENT: 2.6 VELOCITY: (0.0, -0.4, 0.0) DES VELOCITY: (1.7, 0.0, -2.0)
    AGENT: 2.6 VELOCITY: (0.0, -0.4, 0.0) DES VELOCITY: (1.7, 0.0, -2.0)
    AGENT: 2.6 VELOCITY: (0.0, -0.4, 0.0) DES VELOCITY: (1.7, 0.0, -2.0)
    AGENT: 2.6 VELOCITY: (0.0, -0.4, 0.0) DES VELOCITY: (1.7, 0.0, -2.0)
    AGENT: 2.6 VELOCITY: (0.1, -0.3, -0.1) DES VELOCITY: (1.7, 0.0, -2.0)


    This output is without obstacle avoidance off, but it appears to happen whether or not obstacle avoidance is used. I'm not sure what would be causing this, but when this does happen, it seems to happen to all navmeshagents that are currently in the scene at the same time, causing strange looking stuttering in the characters on screen.

    If anyone has any idea why this is happening it would be a great help, because if I cannot fix this I will have to ditch unity's new pathfinding completely as this is really a show stopping issue.
     
  2. diablo

    diablo

    Joined:
    Jan 3, 2011
    Posts:
    736
    It's hard to tell without seeing the code. Could it be that the GC is at work?
     
  3. invulse

    invulse

    Joined:
    Nov 29, 2010
    Posts:
    128
    That seems unlikely. I actually pool every object in the game so almost nothing is created or destroyed during the game itself, just disable and re-enabled. Normally I would think this has something to do with my code, but every navmeshagent has the issue at the exact same time for the same duration when it does happen.
     
  4. Jakob_Unity

    Jakob_Unity

    Joined:
    Dec 25, 2011
    Posts:
    269
    Is this still a problem with the latest 3.5 - if so _please_ file a bug with the scene/project - or ping me.

    Cheers..
    /Jakob
     
  5. victorknai

    victorknai

    Joined:
    Sep 21, 2012
    Posts:
    5
    Just want to let you know that this is still an issue with Unity 4.0 Pro. I have one larger group of navmeshagents chasing another smaller one, and every now and then the larger group will suddenly come to an immediate stop and slowly accellerate back up, giving the smaller group an undesired advantage as they don't stop.
    My game prototype is available on victorknai.webs.com, under the headline Rapid Game Development - Week 1.
     
  6. LVBen

    LVBen

    Joined:
    Apr 1, 2013
    Posts:
    16
    This is happening to me on Unity 4.6.2f1. Sometimes the navigation Agent's desiredVelocity is returning Vector3.zero in cases when there should definitely be a non-zero desired velocity.

    Update: The hasPath value is set to false when it returns the zero vector.
     
  7. youarebritish2

    youarebritish2

    Joined:
    Nov 7, 2013
    Posts:
    29
    Sorry to necro an ancient thread, but I'm still facing this problem in Unity 5.2 and can't find any discussion about this problem. I have verified that the agent is trying to go to another valid location, isPath is set to true, but I'm randomly getting zero from desiredVelocity. This has been a very difficult bug to track down because I can't find a rhyme or reason to what causes it to happen.

    Can anyone suggest a workaround?
     
  8. djarcas

    djarcas

    Joined:
    Nov 15, 2012
    Posts:
    245
    Indeed, I've got this happening. Really no solutions since April 2012?
     
  9. djarcas

    djarcas

    Joined:
    Nov 15, 2012
    Posts:
    245
    And the solution appears to be - don't call Stop on the agent, ever, or it'll never start up again. Just set it's speed to 0.