Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Ryanvanpolen · May 06, 2018 at 07:43 PM · navmeshnavmeshagentruntimeproceduralbaking

Procedural NavMesh Instantiating

Hello everyone,


I'm trying to create a simple procedural map in unity, so I can generate worlds from images. Yet, I do have a problem with creating NavMeshes after I applied the vertices and triangles for the MeshFilter and MeshCollider.


I've tried to find as much as possible about NavMesh generation, but - unfortunately - I concluded that there isn't much diverse content online that could help me solve my problem.


The actual problem


alt text


As you can see in the image above, I created a simple world that has a MeshRender, MeshFilter and MeshCollider applied to it. Right in the bottom left corner I created a cube - displayed in orange - that consists of a MeshRender, MeshFilter, MeshCollider, Rigidbody and a NavMeshAgent. The goal is to get the cube 'walk' to another position (on the same height). Yet, I need to have a NavMesh that grants the NavMeshAgent to 'walk'.


This is the code I'm using:


 public class LevelManager : MonoBehaviour
 {
     // ...
 
     // map requirements
     MeshFilter meshFilter;
     MeshRenderer meshRenderer;
     MeshCollider meshCollider;
 
     // nav mesh agent
     public NavMeshAgent agent;
 
     void Awake ()
     {
         // set up the procedural map
         // ...
         
         // set the nav mesh
         NavMeshBaker navMeshBaker = new NavMeshBaker (gameObject, new Vector3 (30f, 2f, 20f));
         navMeshBaker.Bake ();
     }
 
     void Start ()
     {
         // try to move the nav mesh agent
         agent.destination = new Vector3 (30f, 1.5f, 3f);
     }
 }


And here is my NavMeshBaker Class:


 public class NavMeshBaker
 {
     // nav mesh margins
     public GameObject obj;
     public Transform center;
     public Vector3 buildSize;
 
     // nav mesh data (instamce(s))
     private NavMeshData         data;
     private NavMeshDataInstance instance;
 
     // build source
     private List <NavMeshBuildSource> sources;
 
     // constructor
     public NavMeshBaker (GameObject obj, Vector3 buildSize)
     {
         this.obj = obj;
         this.center = obj.transform;
         this.buildSize = buildSize;
 
         sources = new List <NavMeshBuildSource> ();
         sources.Add (GetLevelBuildSource (obj.transform, buildSize));
     }
 
     public NavMeshBuildSource GetLevelBuildSource (Transform trans, Vector3 size)
     {
         NavMeshBuildSource src = new NavMeshBuildSource ();
 
         src.transform   = trans.localToWorldMatrix;
         src.shape       = NavMeshBuildSourceShape.Box;
         src.size        = size;
 
         return src;
     }
 
     public Bounds GetBounds (Transform trans, Vector3 size)
     {
         return new Bounds (trans.position, size);
     }
 
     
     public void Bake ()
     {
         NavMeshBuildSettings buildSettings = NavMesh.GetSettingsByID (0);
 
         Bounds localBounds = GetBounds (center, buildSize);
 
         NavMeshBuilder.BuildNavMeshData (buildSettings, sources, localBounds, Vector3.zero, Quaternion.Euler (Vector3.forward) );
     }
 
     public void Remove ()
     {
         // yet to be implemented
     }
 }
 

screen-shot-2018-05-06-at-210600.png (330.7 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

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.

Follow this Question

Answers Answers and Comments

90 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

Related Questions

When baking a Navmesh Surface at runtime 'Include Layers' property gets ignored 2 Answers

How to know if a navmesh is baked at runtime? 0 Answers

What is the difference between configuration of agent in 'Agents' tab and in 'Bake' tab Unity? 1 Answer

NavMeshAgent Not Accounting for Objects 0 Answers

Navmesh Pedestrian Crossing 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