- Home /
NavMesh link does not connect properly on runtime
I am using the latest version of Unity 2017.1f1 currently up-to-date.
What I am trying to do
In my 2.5D game, I am spawning enemies that will navigate towards the player while avoiding obstacles (with curving enabled) spawned in runtime. I also spawn a plane (on which the player and enemies moves) additively, I want the current plane navMesh surface to connect to the next spawned plane navMesh surface with a navMesh link so that the enemies can navigate to other planes via the link.
What is the Problem?
There are two issues happening:
The link closer to the obstacle whose curving is
enabled
do not get connected to the next plane.Since the player can run right and left I rotate the plane according to the direction the player is facing, however rotating the plane at 180 degrees, while it's direction is equal to
Vector3.Down
(which is (0,-1,0)) the navMesh links on that plane do not connect to its neighboring planes in runtime.
My Implementation
First of all, I am using the navMesh components provided by Unity on GitHub to achieve this in runtime. Now when I spawn the plane additively I first build the navMesh surface then update its attached links.
nextPlaneSurface.BuildNavMesh();
for (int i = 0; i < nextPlaneLinks.Length; i++) {
nextPlaneLinks[i].UpdateLink();
}
Next, I update the current plane (which the player is on) navMesh links to connect with the newly spawned plane navMesh surface.
for (int i = 0; i < currPlaneLinks.Length; i++) {
currPlaneLinks[i].UpdateLink();
}
What I have tried to fix the problem
For the first problem:-
Updating the current links and rebuilding the navMesh before and after spawning the obstacles.
Updating only the current links before and after spawning the obstacles.
For the second problem:-
I am out of clues, I have no idea what's causing this :(
Will really appreciate if anyone can help me out, also if you guys can explain what's happening internally in the unity scripts that will be really helpful. After all, I am having these problems because I don't understand the concept properly.
Answer by F_J · Apr 10, 2018 at 01:28 PM
I finally found the solution to my problem, the reason why I wasn't able to link the two planes was that the Navmesh surface tile size was too large. After reducing the tile size the link was connecting with the obstacles on the planes.
For a beginner, you can find tile size field under NavMeshSurface component (provided by Unity on GitHub) in advance section.