Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Agent Won't Take the Shortest Route Between Points

Discussion in 'Navigation' started by Panhypersebastos, Jul 25, 2021.

  1. Panhypersebastos

    Panhypersebastos

    Joined:
    Feb 21, 2017
    Posts:
    44
    I'm trying to set up a simple traffic system for my game where I have a bunch of empty gameobjects set up as waypoints for cars to follow. Most of the time it works but sometimes the cars will take strange curvy routes rather than go directly between the two points.

    I'm using Unity's built in navigation system and have some screenshots below that I hope will illustrate the problem.

    Anyone have any idea what is going on?







     
  2. stiverm

    stiverm

    Joined:
    Apr 27, 2013
    Posts:
    16
    The navmesh system seems to have a number of bugs to be worked out.

    You could try creating a separate navmesh for cars that exist exclusively on the roads. This could be restricted even more by separating the lanes.
     
  3. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Seems like a candidate for a bug report.
     
  4. Panhypersebastos

    Panhypersebastos

    Joined:
    Feb 21, 2017
    Posts:
    44
    I was able to solve the problem by setting all the road meshes as navigation static. This results in a navmesh that is more finely detailed around the roads, so the root of the problem probably has something to do with the navmesh sectors being too "big" for proper pathfinding.
     
  5. snowinrain

    snowinrain

    Joined:
    Jan 17, 2016
    Posts:
    15
    I had the same problem earlier. My workaround is:
    1) Assign NavMeshModifier to streets with Override Area on
    upload_2021-8-8_8-7-5.png

    2) Select applicable Area Mask for your car.
    upload_2021-8-8_8-9-21.png

    3) Rebake your scene.

    Although this worked, NavMesh PathFinding still has the problem to find the shortest path anyway.