Search Unity

AI circling target

Discussion in 'Navigation' started by matthewseaward, May 23, 2016.

  1. matthewseaward

    matthewseaward

    Joined:
    Apr 12, 2013
    Posts:
    50
    Hi,

    I have created an AI agent using the NavAgent. I want this to follow a movable marker that is controlled by the player. Ideally, I want the Agent to follow the marker closely - but will be able to navigate around obstacles.

    Whilst, this works well for normal use, I find that rapid movements of the marker cause the Agent to circle or to behave in random ways. I have added a video (below) to outline the issue and also added an image of my settings.
    The nav agent is updated in the Update function of the targets new position.

    This is my first time using NavAgent so it's probably a simple mistake.

     

    Attached Files:

  2. JBR-games

    JBR-games

    Joined:
    Sep 26, 2012
    Posts:
    708
    I think your problem is Angular speed. Try like 50, i think it might not be able to turn quick enough to actually go to its target, causing it to circle. Note : acceleration will effect turning speed as well.

    Try using something like this if performance becomes an issues if adding alot of agents to a scene-

    Code (CSharp):
    1.  
    2. //updates only 5 times a second
    3. InvokeRepeating("NavmeshUpdate",0.2f);
    4.  
    5. Void NavmeshUpdate(){
    6. NavmeshAgent.setDestination(target.position);
    7. }