Search Unity

Move agent next to object?

Discussion in 'Navigation' started by Juliogr, Dec 18, 2019.

  1. Juliogr

    Juliogr

    Joined:
    Mar 8, 2018
    Posts:
    1
    Is there a way to move an agent next to an object? Like, instead of heading towards the center of an object, it stops in a radius next to it?
     
  2. Mortalanimal

    Mortalanimal

    Joined:
    Jun 7, 2014
    Posts:
    568
    - you can increase your stopping distance in the navMeshAgent settings. But this ofc depends on the target Object size.
    - you can add a collision collider trigure and stop your agent as it Impacts your target.
    - you could use an if function, so stop the Agents once it reaches (DistanceFromTarget - targetRadius) <= 0, or (DistanceFromTarget - targetRadius) <= 1 to give it some space.
     
  3. Karrzun

    Karrzun

    Joined:
    Oct 26, 2017
    Posts:
    129
    If you're using the NavMesh system and your object is an obstacle, you can also use NavMesh.SamplePosition ().