News › Forums › RAIN › General Discussion and Troubleshooting › Adding NavMesh on Procedurally Generated Level on Runtime
Tagged: navMesh
This topic contains 2 replies, has 2 voices, and was last updated by EmpI 3 weeks ago.
-
AuthorPosts
-
May 21, 2022 at 12:20 pm #40415
As it says on the tin.
I’m looking for solutions for my game which has levels that are all procedurally generated on Runtime. Every time “play” is clicked in the Editor, a new level is created. I’d like for every time I click “play” for a navmesh to be built around the level, with holes cut inside the walls.
I would also like for enemies which I already have randomly spawning in the level to move about and wander randomly (the idea I have is to randomly set their destination to random tiles on the map, and every time the enemy reaches that destination, the destination jumps to another random spot.)
The second paragraph i’m confident I can handle on my own with simple C# programming, but for the first paragraph, I wouldn’t know where to begin. So help?
May 22, 2022 at 8:23 pm #40420Here you go
http://rivaltheory.com/forums/topic/using-rain-with-terrain-generated-at-runtime/
and here is the code I’ve been using
using System; using UnityEngine; using System.Collections; using RAIN.Navigation.NavMesh; public class NavMeshBuilder : MonoBehaviour { private NavMeshRig _navMeshRig; [SerializeField] private int _threadCount = 4; private int _timeToCreate; public static NavMeshBuilder Instance { get { return _instance; } } public delegate void NavMeshBuilt(); public event NavMeshBuilt OnNavMeshBuilt; private static NavMeshBuilder _instance; private void Awake() { if (_instance != null) { DestroyImmediate(gameObject); return; } _instance = this; } public void GenerateNavMesh(NavMeshRig pNavMeshRig) { _navMeshRig = pNavMeshRig; StartCoroutine("GenNavMesh"); } IEnumerator GenNavMesh() { _navMeshRig.NavMesh.UnregisterNavigationGraph(); float m_startTime = Time.time; _navMeshRig.NavMesh.StartCreatingContours(_threadCount); while (_navMeshRig.NavMesh.Creating) { _navMeshRig.NavMesh.CreateContours(); _timeToCreate++; Debug.Log(string.Format("creating nav mesh..{0}", _timeToCreate)); yield return new WaitForSeconds(1); } if (OnNavMeshBuilt != null) OnNavMeshBuilt(); float m_endTime = Time.time; Debug.Log(string.Format("NavMesh built in {0}s", (m_endTime - m_startTime))); _navMeshRig.NavMesh.RegisterNavigationGraph(); _navMeshRig.Awake(); } public bool IsNavMeshCreating() { return _navMeshRig.NavMesh.Creating; } }
- This reply was modified 3 weeks, 1 day ago by blockcipher.
- This reply was modified 3 weeks, 1 day ago by blockcipher.
May 23, 2022 at 2:10 pm #40426I got it to work! Excellent.
-
AuthorPosts
You must be logged in to reply to this topic.