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 toVector3.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][1] 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*.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*.UpdateLink();*
}
*[1]: https://github.com/Unity-Technologies/NavMeshComponents*_
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.