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
0
Question by HumpaJac000 · Aug 07, 2020 at 02:41 AM · nav mesh

How do I Find the distance from A NavMesh to a destination using NavMesh.CalculatePath

I am trying to make my Enemy character calculate the distance to a way point and if it can complete a path. The problem is that it doesn't seem like a path is being calculated. When I set the way point the character moves there no problem, but I can't get the distance to it. In the attached photo you can see that the debug PathComplete is not there, and the path length is 0. Any help is greatly appreciated, thank you for your time.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.AI;
 
 public class WayPoint : MonoBehaviour
 {
     Vector3 pos;
     Vector3 target;
     float pathLength;
     NavMeshPath path;
     public GameObject npc;
     
     void Start()
     {
         
     }
 
     void Update()
     {
         
     }
 
     public void OnTriggerEnter(Collider other)
     {
         if(other.tag == "WayPoint")
         {
             Debug.Log("WayPointFound");
             pos = npc.transform.position;
             target = other.transform.position;
             path = new NavMeshPath();
             pathLength = 0.0f;
 
             NavMesh.CalculatePath(pos, target, NavMesh.AllAreas, path);
 
             if(path.status == NavMeshPathStatus.PathComplete)
             {
                 Debug.Log("PathComplete");
                 for(int i = 1; i < path.corners.Length; i++)
                 {
                     pathLength += Vector3.Distance(path.corners[i - 1], path.corners[i]);
                 }
             }
             Debug.Log("FinalPathLength" + pathLength);
         }
     }
 }![alt text][1]


[1]: /storage/temp/164928-unity-help.jpg

unity-help.jpg (111.9 kB)
Comment
Add comment · Show 2
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 Ymrasu · Aug 07, 2020 at 04:50 AM 1
Share

Debug.Log the path.status; If it is partial, check how close the last corner is to the target destination. $$anonymous$$aybe it doesn't exactly reaches the target but just looks like it does when you set the path.

avatar image HumpaJac000 Ymrasu · Aug 07, 2020 at 05:48 PM 0
Share

I did this and got PathInvalid. Why could this be, if I set the same waypoint the character walks right to it.

1 Reply

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

Answer by HumpaJac000 · Aug 07, 2020 at 09:50 PM

Solved it, The Enemy has obstacles on it preventing the path from being completed. *Face Palm

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

132 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Fixed obstacles on a navmesh 1 Answer

Interactable object as navmesh obstacle.,How can I make an object interactable while it's a navmesh object? 0 Answers

Can you access generated off mesh links? 0 Answers

How to handle many navmeshes in 1 scene ? 1 Answer

How to set different Navigation Areas for the Dynamic NavMesh? 0 Answers


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