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 modav6 · Mar 11, 2021 at 06:21 AM · navmeshnavmeshagentclosest

Finding the nearest reachable point in a particular NavMesh area

Hi there,

I have a NavMesh consisting primarily of a variable height 'land' mesh, and a 'water' plane intersecting it. The land mesh is traversed by NavMeshAgents in search of food and water. I'm trying to figure out how to find the closest reachable point on the water plane to a particular NavMeshAgent.

The water plane underlies the entire map and is only visible in areas where the land mesh is sufficiently low in height. Because of this, functions like Physics.ClosestPoint() are problematic, because the point returned will always be underground (directly below the NavMeshAgent).

I've also considered collecting a sample of positions falling within a certain radius of the NavMeshAgent and using ray casting to determine if there's water at any of the points. I think this should work, but it's not terribly precise, and will require a pretty substantial number of rays as I increase agent count.

See below for a photo of my scene - red slime NavMeshAgent in search of the nearest watering hole, which is roughly at the red X.

Does anyone have any thoughts on this?

Thanks!

alt text

screen-shot-2021-03-10-at-100721-pm.jpg (314.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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by modav6 · Mar 11, 2021 at 07:58 PM

After some further thought, I think I'm going to try a height-based approach:

  1. If the agent is thirsty, select a random position on the X & Z planes within a certain radius of the agent.

  2. If that position happens to be water (determined through raycasting from above), navigate to it using NavMeshAgent.SetDestination(). I have it set so that agents can't traverse 'water' area masks, so I believe this will take the agent right to the edge.

  3. If the position isn't water, but is lower in elevation, navigate to it. The agent should be getting closer to water.

  4. If the position is higher in elevation, find a new position.

This has a few limitations:

  • If the agent finds itself in a lowland, and it doesn't have sufficient search radius to escape it, it'll end up in an endless loop.

  • This only works if all water is lower in elevation than all land (no mountain lakes).

I've also learned that many animals satisfy all of their water requirements through the food they eat, dew accumulation, rain, the moisture in the air, etc., and do not require standing bodies of water to drink from. Food for thought if anyone happens to read this far :-).

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

120 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

Related Questions

Can't get NavMeshAgent move. NavMeshAgent ignores destination property 7 Answers

NavMesh Jumping Unity Indie 0 Answers

NavMesh giving jerky like motion 0 Answers

Toggling NavMeshAgent and NavMeshObstacle 2 Answers

check if agent reach destination 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