Search Unity

How to make a NavMeshAgent follow a custom path?

Discussion in 'Navigation' started by FeastSC2, Nov 13, 2019.

  1. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    679
    Is there a way to make an agent move along a path that's not linear? I have a list of points that draw a cicular movement and I'd like the agent to go along that path.

    How can I create a NavMeshPath with custom points?
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    589
    Do you specifically need to create a custom path, or is it enough to get the agent move on a route that passes through those points? If that latter option is ok, you could probably think about using some basic patrol route style approach? Just make the agent travel from point to another; when it's close enough to the first point, set the next waypoint. And repeat until you have no waypoints left in your list. When you have many points it will appear as if it's not linear.
     
  3. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    107
    https://docs.unity3d.com/540/Documentation/ScriptReference/NavMeshAgent.SetPath.html

    Assign a new path to this agent.

    If the path is succesfully assigned the agent will resume movement toward the new target. If the path cannot be assigned the path will be cleared (see ResetPath).

    It still linear, there is no path that is not linear, but you can play with angle velocity to smooth it.

    More that that, disable agent position update, just move agent and set NavMeshAgent.NextPosition = transform.position

    its all in docs
     
    Last edited: Nov 13, 2019
  4. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    679
    I can't create a new path with custom points.

    Maybe there's something to be done with nextPosition.. I'll try it out and let you know.
     
  5. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    679
    I would like to try not doing it this way but it will be my last resort if there is no other way.
     
  6. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    107