• 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 jimjames · Feb 14, 2015 at 11:33 AM · navmeshnavmeshagentfloat

NavMesh "remainingDistance" Reset?

Dear: Reader

I am getting this problem as with my agents "remainingDistance" as it always reaches infinity after I run a "agent.ResetPath();" due to placing something ingame to block its path. Here is the important part of my code that you might need to see:

 public Transform target;
 private NavMeshAgent agent;
 public float agentTravelled;
 
 void Start () 
 {
     agent = GetComponent<NavMeshAgent>();
 }
 
 void Update () 
 {
     agent.destination = target.position;
     
     agentTravelled = agent.remainingDistance;
 
     if(agent.isPathStale == true)
     {
         agent.ResetPath();
     }
 }

I need the float "agentTravelled" to not go infinity. The bit that confuses me is that the agent finds a new path and continues to the target, but the float goes infinity "0" and stays like that untill it passes the object that blocked its path. I need the float "agentTravelled" to be accurate to use from other scripts.

Thanks: James

Comment
Add comment · Show 5
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 jimjames · Feb 14, 2015 at 03:42 PM 0
Share

BU$$anonymous$$P...I really need to know how to fix the infinity and reset it.

avatar image jimjames · Feb 14, 2015 at 05:11 PM 0
Share

I tried "agent.updatePosition". But im getting an error: error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement

Can someone help me here? I really am stuck and cant go further in project.

avatar image jimjames · Feb 14, 2015 at 06:42 PM 0
Share

This is the first question I have posted that has taken this long to not even get an answer. I am not explaining the problem correctly, or is this a bug?

please, i need help on this.

avatar image Mmmpies · Feb 22, 2015 at 07:57 PM 0
Share

Only way I can get it to go to 0 is placing a target off the Nav$$anonymous$$esh but my test is very simple and has no obstacles on it.

avatar image jimjames · Feb 22, 2015 at 10:49 PM 0
Share

The problem is not getting it to go to zero. That is the problem. What I am trying to do it restart it after it goes zero. It happens when I place an object on the navmesh with "carve" checked.

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

20 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

Related Questions

NavMeshAgent not fully reaching destination, thus it won't delete itself when it gets there 1 Answer

NavMesh Agent Obstacle Avoidance Ignore 1 Answer

Navigation Agent "Clipping" (Going inside) Navmesh Deadzone?... 1 Answer

Deleted component errors, yet component is still visible in inspector? 0 Answers

NavMesh Lookat causes jittery glitch in character 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