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 justinl · Sep 12, 2012 at 09:53 PM · navmeshnavmeshagentpathfinding

How does NavMeshAgent.SamplePathPosition work?

I'm trying out the Unity (Pro) NavMeshAgent and I've hit a road block with the NavMeshAgent.SamplePathPosition() function.

From what I understand, the purpose of this function is to examine a specific area of the path that is X units in front of the agent along the path to the agent's destination. Is this correct? (If not please point me in the right direction)

If my presumption is correct, I've set up an object (myAgent) and applied the NavMeshAgent component, and I have created a target (myTarget) for it in my scene.

Here is my code that is attempting to test the location 10 units in front of my agent along the Agent path:

 NavMeshHit navhit;
 
 myAgent.SamplePathPosition(NavMesh.GetNavMeshLayerFromName("Default"), 10f, out navhit);
 
 Debug.Log(navhit.position); //this is the same as myAgent.transform.position




However, it seems that no matter what value for the MaxDistance (the 10f), the position that is being tested is always the location of the Agent. Am I totally using this function incorrectly?

My ultimate goal is to look ahead on the agent path and get the Vector3 position of the navhit.

Thank you for any help you can provide.

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

1 Reply

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

Answer by spolglase · Sep 04, 2013 at 08:15 PM

The method actually works perfectly fine. The documentation is just terrible. You need to bitshift the layer. Typically you are trying to query the default layer so it would look something like this:

1 << NavMesh.GetNavMeshLayerFromName("Default")

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 justinl · Sep 04, 2013 at 08:20 PM 0
Share

Thanks! It only took almost exactly 1 year for the answer :)

avatar image spolglase · Sep 04, 2013 at 09:15 PM 0
Share

Haha...yeah sad.

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

11 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

Related Questions

NavMesh area, walkable but not accessible. 2 Answers

NavMeshAgent and NavMeshObstacle together, unit jumping a small distance on toggle 2 Answers

Is there a limit on how far a navmesh agent can go? 0 Answers

Getting a navmeshagent back on a navmesh. 1 Answer

SetDestination's and CalculatePath's Path State Return Works Too Late 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