Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 unity_ZlNDOyAefFicCQ · Mar 03, 2021 at 05:14 PM · navmeshtriangles

Sorting through the triangles of a NavMesh to get a single triangle from a specific area?

Okay so I undertstand how I should be doing this:

  • NavMeshTriangulation.areas is an int[], each element corresponds to a triangle on the Navesh, with each int indicating the area (NavMeshTriangulation.areas[16] could be part of area 5 for example).

  • NavMeshTriangulation.indices is an int[], in groups of 3 they correspond to the indices of the
    vertices (NavMeshTriangulation.indices[0] through [5] would be { 0, 1, 2, 0, 2, 3 } for a square.

  • NavMeshTriangulation.vertices is a Vector3[] containing the vectors of all the verts.

So to draw a ray for each vertex of an area I would:

  • Loop through the area[] to see if the index matches my area (5), store the index in a List or something.

  • Loop through the indices[] (using the stored area ints to make sure I'm looking at the right triangle), store the index in another List, plus the two indexes after (to make a triangle).

  • Finally use the stored values in the second list to Debug.DrawRay() the vertices.

However I've tried doing this and it keeps coming out wrong. I can draw a ray for every vertex on the NavMesh no problem, when I try and do it for a specific area it draws the rays on points other than that.

I'm probably just messing up a really silly calculation somewhere but if I do it by hand it all checks out.

Here's a very broken down version of my code that I made to make sure everything looked good: https://hatebin.com/bjrijwiveq

Thank you for any help!

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
Best Answer

Answer by unity_ZlNDOyAefFicCQ · Mar 04, 2021 at 05:52 PM

Turns out that I was just getting confused and mixing up some of the vertex Vectors, here's the basic code to put a ray on each point of a specific area (In this case area 5):

for (int i = 0; i < navMeshTriangulation.areas.Length; i++) { if (navMeshTriangulation.areas[i] == 5) { int j = i * 3; for (int x = 0; x < 3; x++) { Debug.DrawRay(navMeshTriangulation.vertices[navMeshTriangulation.indices[j + x]], Vector3.up, Color.blue, 30.0f); } } }

It would be really usefull if you could somehow see the triangles with their index in the editor, but this shall suffice.

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 unity_240503umar · May 18 at 12:52 PM 0
Share

Can you please explain indices? I got a task to draw all outline vertex and i am not sure what are these indices and vertices about..

avatar image unity_240503umar · May 18 at 12:53 PM 0
Share

And can you please send the code one more time?

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

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

How to get AI to wander randomly around a point with NavMesh? 0 Answers

Is Removing Ngons a Good Thing to do in Unity? 0 Answers

Nav Mesh Agent destination not lining up with actual target. 1 Answer

Navmesh How to check if full path available? C# 5 Answers

Is there a way to make a follow script without NavMesh? 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