Dynamic placement of AI


I did some searching around, but it did not yield anything use full.

I would really like to know how one is supposed to create a dynamic Instantiation system, which automatically finds the next set of spawnpoints around you and spawn AIs. Let me brake it down for you my friend:


  • Player passes a trigger called “Place_AI”
  • Find near by spawn points(empty gameObjects)
  • Instantiate enemys of different types at said spawn points

However I am having some trouble figuring out the details I guess.

When the player passes the trigger, how would one find the spawn points for AIs close to the players position without “hard coding” it? And how would one easily tell the computer to spawn 2 of these AIs and 3 of these AIs?

What I have now in basic is this:

var count = 0;
var enemy : Transform;

function OnTriggerEnter (hit : Collider) {
    if(hit.gameObject.tag == "Place_AI"){

function PlaceAI(count : int){
        case count:
            Instantiate(enemy, saidSpawnPoints.transform.position, transform.rotation);

(I know there is a lot of redundancy, no need pointing that out ;))

But how would I find the spawns point relevant to my position dynamically?
And how can I easily tell the computer to Instantiate x of these AIs and y of these AIs? While everything is as dynamic as possible(meaning not hard coded).

I hope you get what I am saying. I could really appreciate some help on this one.

Thank you.

What I do is have Spawnpoint objects (use the Editor to assign a nice icon for them), then assign them to an Array of Transform in my spawner script. There, you can pick random points, the ‘next’ point (round-robin), closest point, whatever. To find closest point, you loop through the array calling Vector3.Distance using the spawn point position from the array, and the current player position, keeping track of the smallest distance.

BTW You can also use the rotation of the spawnpoint object as the initial rotation of your spawned bot (or whatever). For this I have a gizmo that draws an arrow in that direction for ease of authoring.