Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Vurbefef · Oct 02, 2015 at 09:09 PM · navmeshnavigationtower-defense

Unity Navigation stopping distance irregularity

http://www.mediafire.com/watch/logqpz9t49v8pct/UnityNavMeshError.mp4 ^(A video of my problem)

 #pragma strict
 
 var agent: NavMeshAgent;
 
 var gos1 : GameObject;
 
 var gos2 : GameObject;
 
 function Start () {
 }
 
 function Update () {
 
     // Find all game objects with tag Enemy
     var gos : GameObject[];
     gos = GameObject.FindGameObjectsWithTag("Enemy");
     var closest : GameObject;
     // Iterate through them and find the closest one
     for (var go : GameObject in gos)  {
 if(gos1 == null){
     gos1 = go;
     } else if(gos2 == null && gos1 != go){
     gos2 = go;
     var distance1 = Vector3.Distance(gos1.transform.position, transform.position);
     var distance2 = Vector3.Distance(gos2.transform.position, transform.position);
     if(distance1 > distance2){
         gos1 = gos2;
         gos2 = null;
     }
     gos2 = null;
     }
 
 }
     agent.SetDestination(gos1.transform.position);
 
     
 
 }



Hey guys! I'm just trying to make a tower defence game not unlike boom beach by Supercell, but I'm having a problem with the Navigation! For some reason, the players(Navigation Objects) are moving to weird places on the objects e.g. the left side of a cube etc.

The code included is the script attached to the players(Navigation Objects) Thanks!

Comment
Add comment · Show 21
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 Oribow · Oct 02, 2015 at 09:48 PM 0
Share

$$anonymous$$ay its a problem with your navmesh. Some of your agents, doesen't seem to move at all. $$anonymous$$ay they cant find a path and thats the reason why? There is definetly no problem in your code, besides it's a bit clunky.

avatar image Vurbefef Oribow · Oct 02, 2015 at 09:54 PM 0
Share

I've tryed different bases(cubes used as floors) with other cubes on top, same thing. What do you suggest?

avatar image Oribow · Oct 02, 2015 at 09:54 PM 1
Share

Have you rebuild your navmesh before trying?

avatar image Vurbefef Oribow · Oct 02, 2015 at 09:56 PM 0
Share

If you mean re-baking, then yes.

avatar image Vurbefef Oribow · Oct 02, 2015 at 10:07 PM 0
Share

I could provide you with a picture of the navmesh tomorrow, will that help?

avatar image Oribow · Oct 02, 2015 at 10:10 PM 0
Share

Could you try out this code? Its does basicly the same, but works different. Its written in C#, when thats a problem. private GameObject currentDest; public Nav$$anonymous$$eshAgent agent;

     void Update()
     {
         GameObject[] allEnemys = GameObject.FindGameObjectsWithTag("Enemy");
         if (allEnemys.Length == 0)
             return; // There is no enemy
         currentDest = allEnemys[0];
         float bestDistance = Vector3.Distance(transform.position, currentDest.transform.position);
         for (int i = 1; i<allEnemys.Length; i++)
         {
             if (bestDistance > Vector3.Distance(transform.position, allEnemys[i].transform.position))
             {
                 currentDest = allEnemys[i];
                 bestDistance = Vector3.Distance(transform.position, allEnemys[i].transform.position);
             }
         }
         agent.SetDestination(currentDest.transform.position);
     }
avatar image Vurbefef Oribow · Oct 02, 2015 at 10:13 PM 0
Share

Yes, I did think about the code as a problem, so I tryed just a simple setdestination just to the shere, same thing happened.

avatar image Oribow · Oct 02, 2015 at 10:17 PM 0
Share

Then it must be a problem with your navmesh! The picture would help greatly.

avatar image Vurbefef Oribow · Oct 02, 2015 at 10:19 PM 0
Share

O$$anonymous$$, I'll send you a picture ASAP, I'm away from my computer for a day so I'll reply a link to this page!

avatar image Vurbefef Oribow · Oct 03, 2015 at 10:53 AM 0
Share

Here is the Nav$$anonymous$$esh Image: http://www.mediafire.com/view/hxdv73668yj1s8m/Nav$$anonymous$$esh.PNG

avatar image Oribow Vurbefef · Oct 03, 2015 at 02:27 PM 0
Share

Could you debug this line like this. If the output is false, then the point the agents wants to move to, is not on the navmesh. Debug.log(agent.SetDestination(currentDest.transform.position));

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Oribow · Oct 03, 2015 at 04:57 PM

Ok, I now know your problem: There isn't one, at all. It's just how the system works. The stopdistance on your agent kicks in, if the remaining path lenght is smaller than the stop distance. But the remaining path lenght isn't nescesary the same as the direct air distance between your agent and your Object. (look at the Screenshot). This code is a work around that. Just set the stop distance on all of your agents to zero. The script will stop the agent, when the direct air distance is smaller, than "minimumDistance" alt text

 #pragma strict
 
 var agent: NavMeshAgent;
 
 var gos1 : GameObject;
 
 var gos2 : GameObject;
 
 var minimumDistance : float;
 
 function Start () {
     // Find all game objects with tag Enemy
     var gos : GameObject[];
     gos = GameObject.FindGameObjectsWithTag("Enemy");
     var closest : GameObject;
     // Iterate through them and find the closest one
     for (var go : GameObject in gos)  {
 if(gos1 == null){
     gos1 = go;
     } else if(gos2 == null && gos1 != go){
         gos2 = go;
         var distance1 = Vector3.Distance(gos1.transform.position, transform.position);
         var distance2 = Vector3.Distance(gos2.transform.position, transform.position);
         if(distance1 > distance2){
             gos1 = gos2;
             gos2 = null;
         }
         gos2 = null;
 }
 }
     agent.SetDestination(gos1.transform.position);
 
 }
 
 function Update () {
     if(Vector3.Distance(gos1.transform.position, agent.transform.position) < minimumDistance)
         agent.Stop();
    
 }



navmesh.jpg (41.3 kB)
Comment
Add comment · Show 2 · 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 Vurbefef · Oct 03, 2015 at 05:05 PM 0
Share

Wow. that simple.

alt text

Thanks!

double-face-palm.jpg (14.4 kB)
avatar image nanodeath · May 13, 2020 at 06:25 PM 0
Share

5 years later...yeah, this looks right. I think most of us interpret stopping distance as a "ring" around the destination, and that the agent should try to land right on the edge of the ring, when in fact it's more of a hint to the agent how close it needs to be to the destination. That is, if the agent is already within stopping distance of the destination, it shouldn't try to get any closer.

Also, in Unity 2019, it should be agent.isStopped = true.

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

31 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 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

Navmesh agent passing through obstacles (path goes under navmesh) 1 Answer

Navigatin Mesh agent works for ~10 seconds, then starts moving sporadically 0 Answers

Navmesh, need an destroyable obstacle which will remove it's entity in terms of NavMeshPath 2 Answers

Nav meshes in ECS/DOTS 0 Answers

RayCast not accurate on non-colliders (3D) 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