Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Imawizrd · Aug 22, 2013 at 07:20 AM · navmeshnavmeshagentpathfindingroute

NavMeshAgent not calculating shortest route.

Hi !

I'm having trouble with Unity's NavMeshAgent / NavMesh. My agent's do not seem to be finding the fastest route to their destination. Bellow are some screen shots of what I am experiencing.

Here is what I'm experiencing. Please ignore the tween paths (pink and bright red lines).

top image, the cube that is going through the gap was spawned closer to the end point. so it seems to have found the fastest path. The agent that was further back has decided to take the scenic route.

The middle image shows that it's consistent every time they spawn and I run the scene.

The bottom image shows the nav mesh itself. Ignore the light blue shade on the NavMesh I've have since removed that and still receive the same results.

alt text

Here are my NavAgent details:

alt text

I believe the code is unrelated. I've tried both updating their destinations with SetDestination and only setting it when I spawn them.

I just noticed the image of the NavMesh doesn't show the end point. The end point is on the NavMesh.

path07.png (80.6 kB)
agentsetup.png (12.9 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by jstopyra · Jul 27, 2017 at 05:34 PM

Was this ever solved? I'm having the same issue and can't find a solution for it.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by drewjosh · Oct 29, 2020 at 04:12 PM

There is a solution I found in the Unity Docs: NavMesh.CalculatePath

You can tell Unity to calculate the path new. Although it recommends to do it only every second, otherwise it could cause problems with frame rate:

 // ShowGoldenPath
 using UnityEngine;
 using UnityEngine.AI;
 
 public class ShowGoldenPath : MonoBehaviour
 {
     public Transform target;
     private NavMeshPath path;
     private float elapsed = 0.0f;
     void Start()
     {
         path = new NavMeshPath();
         elapsed = 0.0f;
     }
 
     void Update()
     {
         // Update the way to the goal every second.
         elapsed += Time.deltaTime;
         if (elapsed > 1.0f)
         {
             elapsed -= 1.0f;
             NavMesh.CalculatePath(transform.position, target.position, NavMesh.AllAreas, path);
         }
         for (int i = 0; i < path.corners.Length - 1; i++)
             Debug.DrawLine(path.corners[i], path.corners[i + 1], Color.red);
     }
 }

@jstopyra (my answer is kinda late, but it's never too late)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Akvavit · Jul 27, 2017 at 07:06 PM

Well I'm no expert on the navmesh since I always make my own path finding but my guess is because it's not supposed to find the shortest route. Finding the shortest route is very expensive, and what pathfinding algorithms are usually doing (like A*) is finding a good path, fast. If you want the 100% the shortest path you probably want to look up Dijkstra's algorithm. But if it is a realtime (not turnbased) game I wouldn't use it since it is very expensive.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Recentering an infinite world that has a NavMesh. 0 Answers

Use Fog of War to Restrict NavMesh Per-Agent 0 Answers

NavMesh agent Pathfinding Zombies 1 Answer

How to use Unity's pathfinding system without NavMeshAgent controlling my character? 1 Answer

How to check if Navmesh finished baking realtime ( in playmode ) ? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges