Cross posted on StackOverflow
I make a tower defense style game in 3D with Unity. I encounter a frustrating problem with the appearance of a large number of characters in a navmesh area where, if I get too close to the same place, many of them will 'teleport' "immediately after instantiation to get closer to the destination navmesh.
Here is a doodle of one of the levels:
The black dot is the base of players that NPCs must go to. The green landscape has no navmesh and uses mesh colliders. The landscape consists mainly of steep hills forming a valley that NPCs must cross. It is composed of several meshs marked Unwalkable in the navigation. The big blue spot is the first nesting site I've tried. I then tried a larger area shown in the right side of the image (see "What I've tried" below).
When instantiating at the original respawn location, if I generate more than twenty NPCs at the same time, many of them will go to the indicated area by the red dots.
NPCs have a radius of about 1.5 m, as do their colliders and their navmeshagent avoidance properties.
Things I've tried:
- Spawn at a random position inside a 50m radius circle.
- Adding a new large hidden area of navmesh as in the picture above,
define a table of well-spaced and reproducing vector positions
at each position, in turn, there are not two ships that appear near each ship.
- Add a delay to
after instantiation hoping that this would prevent the immediate jump towards
near the destination.
- Reduction of the radius of avoidance of marine vessels. This
reduces the problem a bit but still, even with a radius of 0.1 all
more than 50 NPCs are causing the problem.
- By increasing the time between instantiations, a large gap of several seconds works, but makes the game too easy.
How can I generate a large number of ships in a short period of time, avoiding this "teleportation" behavior?