Cross posted on StackOverflow
I am making a tower protection type sport in 3D utilizing Unity. I am experiencing a irritating difficulty with spawning giant numbers of characters in an space of navmesh the place if I spawn too many close to the identical location lots of them will ‘teleport’ instantly after instantiation to close the navmesh vacation spot.
Here is a doodle of one of many ranges:
The black spot is the participant base the NPCs should get to. The inexperienced surroundings has no navmesh and makes use of mesh colliders. Surroundings is usually steep hills forming a valley the NPCs ought to path via. It’s composed of a number of meshes marked Unwalkable in navigation. The massive blue spot is the primary spawn location I attempted, I later tried a bigger space indicated in the fitting aspect of the picture (see ‘issues I’ve tried’ beneath).
When instantiating on the authentic spawn location if I spawn greater than about 20 NPCs without delay lots of them will soar to the the realm indicated by the purple spots.
The NPCs have a radius of about 1.5m, as do their colliders and navmeshagents avoidance property.
Issues I’ve tried:
- Spawning to a random place inside a circle with a radius of 50m.
- Including a big new hidden space of navmesh as within the picture above,
defining an array of vector positions unfold effectively aside and spawning
at every place in flip so no two navmeshagents spawn close to every
- Including a delay to
after instantiation hoping this might forestall the instant soar to
close to the vacation spot.
- Lowering navmeshagents avoidance radius. This typically
reduces the issue a bit of however nonetheless, even with a radius of 0.1 any
greater than round 50 NPCs triggers the issue.
- Turning avoidance off althogether (setting to none in navmeshagent), once more, can spawn extra however downside nonetheless occurs
- Turning off auto traverse hyperlinks and auto repath in navmeshagent
- Rising the time between instantiations, a big hole of a number of seconds works however makes the sport too straightforward
- Not setting a vacation spot – oddly they nonetheless teleport to close the participant base, so I assume vacation spot is just not an element
How can I spawn giant numbers of navmeshagents in a brief timeframe, avoiding this ‘teleporting’ behaviour?