- Home /
Random AI spawning, random object spawning
Hi,
I have a question, in left for dead 2 they have random spawning of objects/weapons and zombies/AI ex: the AI and weapons are in different areas each time you join a different game and some times a area is blocked off when you join a game then the next time you join it is not blocked off, so my question is how would you make random spawning like in left for dead 2 if you have any idea on any of the three things im asking please replay, random zombie spawn, random objects, random barricades,
Answer by hvilela · Sep 27, 2012 at 10:16 PM
Using Random you can randomize anything you want.
Get a ramdom zombie from a zombie list:
GameObject randomZombie = zombieList[(int) (Random.value * zombieList.Lenght));
Or position in a random position: (assuming your level is 100x100)
zombie.transform.position = new Vector3(Random.value * 100, 0, Random.value * 100);
Or anything at all... have fun! :)
thank you vary much,
but can I just take one of my zombies and add that script.
GameObject randomzombie = zombielist[(int) (Random.valvue * zombieList.Lenght));
Then he will spawn any were or is there more to it also I dont wont the zombie to spawn out of map so will that happen.
sorry im asking so much qestions but im a noob when i comes to scripting.
thank you :)
The first code line that I've post is to get a random zombie from a random list, the second is to position him in a random position. The "100" is the game field size (depends on your game). You have to adjust things to fit your specific case.
thank you for your quick reply.
I think im getting ahead of my self I will spend more time working with basic random objects.
if you now of any great tutorials about random scripting please send a link or info.