Reputation: 11
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:
enabled
do not
get connected to the next plane.Vector3.Down
(which
is (0,-1,0)) the navMesh links on that plane does 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:-
For the second problem:-
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.
Upvotes: 1
Views: 1809
Reputation: 11
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.
Upvotes: 0