mardi 27 septembre 2016

Spawn gameObject horde, modify concentration of spawned objects

How would I create a non-uniform random generation of gameObjects (enemies) that mimic the formation of a "horde" like this image: enter image description here

I want there to be more gameObjects in the front and less as it trails off towards the back. I thought of making an Empty gameObject and having the enemies target with code like this:

public Vector3 target : Transform;
if (target == null && GameObject.FindWithTag("Empty"))
{
       target = GameObject.FindWithTag("Empty").transform;
}

However, doing that would not give me the "trail" effect where there are fewer int he back.

Here is my code for randomly generating enemies, if it helps:

void SpawnHorde()
{
    for (int i = 0; i < hordeCount; i++) 
    {
        Vector3 spawnPosition = new Vector3(Random.Range (0, 200), 50, Random.Range (0, 200));
        Instantiate(Resources.Load ("Prefabs/Sphere"), spawnPosition, Quaternion.identity);
    }
}

Does anyone have a suggestion as to how to achieve this?




Aucun commentaire:

Enregistrer un commentaire